What happens to running processes when I lose a remote connection to a *nix box?
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 &
David Marble
Updated on September 17, 2022Comments
-
David Marble almost 2 years
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 ascreen
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!