Every process which starts from a terminal is tied to shell as a child process from which it was executed. In the situation when a parent program gets terminated the child process will be terminated also as a result parent process termination.

This is not particularity desired behavior when a user needs to run a process remotely and let the process run after logout. Fir this reason a nohup command exists. nohp ensures that the process is not tied to any particular shell so user can kill shell process by logging out and the process executed with nohup will be kept alive. Syntax for nohup is as follows:

$ nohup my-command > my-command.out &

Note the output file will be created as this will capture any STDOUT coming out from my-command. & returns a shell as it runs my-command on the background. Here is a small example to test this theory:

Run a yes command with nohup and redirect a output to the /dev/null. Make sure that you use & at the end of the command to run the command on the background:

$ nohup yes > /dev/null &
[1] 3594

now close or log out from the terminal, open another session and run a following command:

ps aux | grep yes
lilo 3594 98.3 0.0 3016 504 ? R 11:06 1:23 yes

Note that process PID 3594 is still running. To kill that process run:

kill 3594


Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top