Sam Hooke

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

These are rough notes from whatever I was working on, interested in or thinking about at the time. They vary greatly in quality and length, but prove useful to me, and hopefully to you too!

← Previous: Celery pinging
Next: Run Django ` makemigrations` without a database →