From FreeBSDwiki
Revision as of 12:03, 17 September 2007 by (Talk)
Jump to: navigation, search

nohup is a godsend for those of us who spend lots of time shelling into remote machines. You can invoke any other command with nohup, like the following:

ph34r# nohup find / -name "*a*" > /home/jimbo/dumbfindcommand.out

And what happens is, your command gets executed but told to ignore all SIGHUP signals. The net impact is, you can now close your shell session, and still have your command continue to run - whereas normally, as soon as your shell died - either due to you closing it or to the vagaries of the internet closing it for you - all processes you had running would immediately die as well.

The example given above - give me a listing of every single file on my entire server which contains the letter "a" in its name - would obviously take an absurdly long time to run. If you had to accomplish a task like this on a machine hundreds of miles away, it would be nearly impossible without finding some way of detaching it from your shell session. You could also use the at scheduler, but that can be a real pain because it only fires off every 5 minutes (by default), and you hate to just set something up and walk away without checking to see that it fired up and began doing what it was supposed to. With nohup, you can just fire it up immediately, use a ps or other command to monitor that it is running and appears to be doing what it ought to be doing, and then quit worrying about it 'til it's done.

Another alternative is the GNU screen utility, but that would be geared more towards people who want to attach and detach from shell sessions, not just folks who want a job running in the background to stay alive when not connected.

Yet one more choice would be to add & to the end of your command. For example:

ph34r#find / -name "*a*" > /home/jimbo/dumbfindcommand.out&

This will run it as a seperate process and will let you know what the process number is when started, and when it ends.

Shown when started
[1] 90557 

Shown when ended
[1]    Done                          find / -name "*a*" > /home/jimbo/dumbfindcommand.out&
Personal tools