What happens to running processes when I lose a remote connection to a *nix box?

16

2

I occasionally lose my remote SSH connection to my VPS. I use screen for long-running processes, but am wondering what happens to the processes I had running aside from those run within a screen session if I lose the connection to the box.

When I re-establish a connection to the box, what happened to the bash and sshd processes that were running when I lost the connection? Today I lost connection repeatedly and noticed many more bash and sshd processes than usual.

If there are processes hanging around, do I need to kill them? How could I determine which processes were abandoned from my previous session?

Thanks for any replies!

David Marble

Posted 2010-05-22T00:46:52.257

Reputation: 263

Answers

8

Normally the processes will terminate upon disconnection, but the old SSH sessions could either be waiting to timeout, or they could have hung upon exit, due to a race condition.

You should probably terminate the old sessions, although you don't necessarily have to. Type ps aux on the console to list the processes, then kill PID for each hung ssh session, where PID is the PID (process ID) for that session. The older, hung sessions should have lower PIDs than your current, new session.

If there is a long-running process that you specifically want to continue running even after you disconnect, you can prefix your command with nohup:

nohup badblocks -nvs /dev/sda &

rob

Posted 2010-05-22T00:46:52.257

Reputation: 13 188

0

When the ssh session dies, the pseudo-tty associated is closed and reset. Typically the shell and other processes associated with that tty are killed, as they are child processes of the process that created it. If there are processes hanging around, perhaps they had been backgounded? Yes, they should probably be killed - cleanliness is next to godliness. They do take up some resources - not usually much, but it can add up after awhile.

Shannon Nelson

Posted 2010-05-22T00:46:52.257

Reputation: 1 287