Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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 &
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.