notification upon program completion

6

I'm going to run prog.cpp on my university's Linux cluster (compiled with gcc). I project that the program will take 3-6 days to complete. I was thinking of running it as

./prog &

to run it in the background. My questions are:

  1. Is it safe for me to just close the terminal window?
  2. How do I know when my program is complete? Can I make GCC notify me somehow?

covstat

Posted 2011-11-30T18:26:35.517

Reputation: 61

Answers

12

No, ./prog & isn't enough: you program will get killed when the session ends.

You could use nohup:

nohup ./prog &

A more flexible option is to use GNU screen.

As to email notification, personally I'd write a two-line shell script, the first line running ./prog in the foreground, and the second line using mail to send the notification. Then the script could be run using nohup or within a screen session.

NPE

Posted 2011-11-30T18:26:35.517

Reputation: 1 169

2+1, another 30 secs, and I would have said the same thing. – rcollyer – 2011-11-30T18:30:30.500

A 2-line shell script seems like overkill, IMHO, unless you're going to do this regularly. But that may just be me ... – None – 2011-11-30T18:34:36.320

+1 That would have been my answer. – Yitzchak – 2011-11-30T19:53:50.133

2

Your program has nothing to do with GCC. It has been compiled by GCC but you don't need GCC to run it (and you could have compiled it elsewhere).

you might run

 nohup ./prog

but I really suggest using the batch system (provided by atd thru batch or at commands) e.g.

 batch << END
  ./prog
 END

The atd dameon will send you an email when the batch has completed. With the at command you can also give an hour (when start your progream).

Basile Starynkevitch

Posted 2011-11-30T18:26:35.517

Reputation: 1 022

1

No, it is not generally safe to exit your terminal window when you have a background program running, if you want that background program to continue.

The reason is that when you exit the terminal, you will generally send the program a signal (generally the HANGUP signal, IIRC). Programs, by default, will exit when they get this signal.

As specified in another answer, try using nohup(1) or the screen(1) program, which allows you to disconnect (on purpose or by accident) and reconnect later.

As to email notification, try something like:

nohup sh -c 'prog; echo "all done" | mail -s results yourname@your.domain' &

Lee-Man

Posted 2011-11-30T18:26:35.517

Reputation: 151

0

  1. It is not safe to close terminal window. You should issue disown command, this will remove prog active jobs. And program won't be killed after closing terminal window.

Beginner

Posted 2011-11-30T18:26:35.517

Reputation: 161

0

If you can start your program with zsh terminal and start it with the background command you don't need to worry about nohup or disown command. Zsh is a replacement shell for ash or bash and has some nice feature for example nicer colors for the directory listing to start off. I use it a lot with lighttpd and the background command.

Gigamegs

Posted 2011-11-30T18:26:35.517

Reputation: 1 784

-1

  1. If the programm is running in background I think it's safe then.
  2. Maybe try ./prog && sendmail [opts, I don't now what but U can read documentation] &

Hauleth

Posted 2011-11-30T18:26:35.517

Reputation: 342

-1: as others have said, simply backgrounding a program with & is not enough, and such a program will get SIGHUPed when the shell quits. – Blacklight Shining – 2013-09-20T06:08:13.950