smhk

Avoid a process terminating when logging off a remote SSH session

For any arbitrary command:

nohup <cmd> > cmd_log.txt &

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:

tail -F cmd_log.txt

The nohup command will echo the PID of the background process:

$ nohup tar -xvzf huge.tar.gz > cmd_log.txt &
[1] 31782
$ nohup: ignoring input and redirecting stderr to stdout