nohup is most often used to run script or command in the background as daemons. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected. This command is very helpful when there is a need to run numerous batch jobs which are inter-dependent.
$ nohup ./myscript > mystdoutput.log&
Don't forget the ampersand.
Nohup effectively separate the process from the terminal:
- It closes standard input (the program will not be able to read any input, even if it is run in the foreground. it is not halted, but will receive an error code or EOF).
- It redirects standard output and standard error to the file nohup.out, so the program won't fail for writing to standard output if the terminal fails, so whatever the process writes is not lost.
- It prevents the process from receiving a SIGHUP (thus the name).
nohup doesn't put the job in the background but since a foreground nohup job is more or less useless, you'd generally put it into the background using &. Unlike with disown, the shell will still tell you when the nohup job has completed (unless the shell is terminated before, of course).