Sometimes, we may need ourscriptto run evenafterwe log out, such as when making a backup and similar activities. In this case, even if we log out, the system is powered on and running. In such situations, we can use thenohup
command. Thenohup
command prevents the process from terminating by using theSIGHUP
signal.
Thenohup
command makes our script run without attaching it to a Terminal. Therefore, if we use theecho
command to print text on the Terminal it will not be printed in a Terminal, since the script is not attached to a Terminal. In such cases, we need to redirect the output to the file, ornohup
will automatically redirect the output to anohup.out
file.
Therefore, if we need to run a process, even if we log out, we need to use thenohup
command as follows:
$ nohup command &
The example is as follows:
$ nohup sort emp.lst &
This will run a program to sort the emp.lst
file in the background.
$ nohup date &