AdSense Mobile Ad

Friday, June 11, 2010

SSH Hangs On Exit When Using nohup

I recently discovered how ssh sometimes hangs on exit when I've launched some process with nohup. The first suspect was standard output and it costed me some time to realize that the problem was related to the input stream of the process that I had launched with nohup.

Indeed, I solved the problem (for scripts) by launching commands this way:

$ nohup my-command </dev/null &

After finding a workaround I indeed found that this is a well known "problem" but it's not a bug, insted. As far as I could check, ssh is respecting the POSIX standard when not closing the session if a process is still attached to the tty. Other programs which did not show this behavior, such as some telnet, are behaving in a non-compliant way.

Anyway, the previous workaround is fine for me.

A small tip: Should your (Open)SSH session "hang" in such a situation, you can just use the ~. sequence to disconnect it. Don't worry, your nohup-ed process will keep running anyway.

2 comments:

Stuart said...

If that doesn't work for you try redirecting stdin, stdout and stderr:

nohup /dev/null 2>&1 &

Unknown said...

thanks a lot. it helped a lot.