Unix nohup &

nohup – No Hangup

It is a POSIX command to ignore the hangup signal. This enables the command to keep running ever after the terminal has been logged out.

So if you want to run a deamon process, nohup is the command for you. By default the nohup terminal output goes to a file called nohup.out in the same directory.
Eg:
term$ nohup test.sh
nohup: ignoring input and appending output to `nohup.out’
term$ ls -lrt
total 4
-rwxr-xr-x 1 dsahi dsahi 306 2011-04-19 11:56 test.sh
-rw——- 1 dsahi dsahi   0 2011-04-25 10:35 nohup.out


If you want the output to be redirected to some other file, you need to use the redirection operator.

Eg:
term$ nohup test.sh > test.log
nohup: ignoring input and appending output to `nohup.out’
term$ ls -lrt
total 4
-rwxr-xr-x 1 dsahi dsahi 306 2011-04-19 11:56 test.sh
-rw——- 1 dsahi dsahi   0 2011-04-25 10:35 test.log

nohup is generally used in combination with &, which makes the process to run in background. It’s something like ‘Don’t wait for me to complete’.

Eg:
term$ nohup test.sh &term$ exit

Instantly after triggering the command, you will see the terminal prompt available for you to type in the next command.

Advertisements