May 29th 2008 GNU Screen Revisited

A few months ago, I made a post about how to use GNU screen to run a process in the background after logging out. The directions in that post still work, but I found what I think is an easier solution: the nohup program.

nohup is short for “No Hangup”, and is a way to make programs ignore the Linux SIGHUP signal, the signal sent to all of a user’s processes upon logout. Basically, this means you can keep a process running after logging out of a machine. Its usage is simple:

    $ nohup myprog >myprog.out &
    $ exit

This will run myprog in the background, and write all of its output to the file myprog.out.

nohup has one little problem: If you don’t redirect a program’s output, the shell can hang when you logout. To prevent this issue, redirect stdout, stderr, and stdin, like so:

    $ nohup myprog >myprog.out 2>&1 </dev/null &
    $ exit