nohup
If you, whether interactively or as part of a shell script, want a process to run to completion without being killed because you have logged off, the nohup command informs the shell to ignore any “hangup” (HUP) signals that it would get sent when its controlling terminal logs off the system. It can still be killed with kill -9, but if a network glitch causes your link to the system to be dropped, or the client you are connecting from were to crash, or any of a million other reasons the connection could get broken, your process will continue to run.
This is mainly useful for executing long-running commands on a remote server, or even on multiple remote servers in parallel. Whether using automation or simply a sequence of ssh commands, you can log in to a machine, run nohup /path/to/somecommand & and log out again. The & puts the command in the background; generally, if you are not waiting around for the result of the command execution, it makes sense to run it as a background process. It also means that you get the shell prompt back so that you are able to log out.
By default, any input the process needs to read will be redirected from /dev/null, and output and errors will be written to a file nohup.out in the current directory. If stdout and stderr are both redirected elsewhere, nohup.out will not be created. This recipe simply spawns a long-running command in the background and returns to the menu. The file count appears to stay the same until the background job has completed; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access