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
  • 161

6 Answers6

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
  • 1,239
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).

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
  • 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.
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.

Micromega
  • 1,914
-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
  • 352