Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?
share|improve this question

migrated from stackoverflow.com Nov 30 '11 at 18:38

This question came from our site for professional and enthusiast programmers.

6 Answers 6

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.

share|improve this answer
2  
+1, another 30 secs, and I would have said the same thing. –  rcollyer Nov 30 '11 at 18:30
    
A 2-line shell script seems like overkill, IMHO, unless you're going to do this regularly. But that may just be me ... –  Lee-Man Nov 30 '11 at 18:34
    
+1 That would have been my answer. –  Yitzchak Nov 30 '11 at 19:53

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

share|improve this answer

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' &
share|improve this answer
  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.
share|improve this answer

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.

share|improve this answer
  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] &
share|improve this answer
    
-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 Sep 20 '13 at 6:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.