Avoid a process terminating when logging off a remote SSH session
For any arbitrary command:
The &
forks <cmd>
into a separate process, and nohup
(“no hang up”) ensures the process does not terminate once you log out. This can be useful to, for example, SSH into a remote machine and launch a long running command, without forcing you to keep the session open.
The stdout of the process can be viewed live by tailing the log:
The nohup
command will echo the PID of the background process: