I'm developing with vi over ssh.

My problem is that sometimes I get my ssh connection killed because of my poor wifi connection and previous processes (like "top", "rails c", etc...) are not being killed properly.

So after a little while, i get those processes at 100% of the CPU usage (i don't really know why), and I need to kill them manually.

Because I'm not the only developer, it can get really messy so my boss asked me to come up with a solution.

How would i do this?


There are several ways around this:

  1. Kill the leftover processes.
  2. Use something to compensate for the disconnections.

The second option is the easiest with screen or tmux.

After your connection has dropped you reconnect, log back in and resume your screen/tmux session, then continue working where you left. (For screen use screen -r to resume).

If you ever used remote desktop in windows, then you can compare this with resuming a disconnected RDP session.

  • I also use screen in such situations as well. Good answer. +1. – Michał Šrajer Jul 31 '12 at 14:57
  • Can you tell me how to kill the leftover processes? – boby lapointe Aug 1 '12 at 13:42
  • First get the process ID of the leftover process. Use can use a command such as ps for this. Then use 'kill -1 processID. This will send the process a SIGHUP. Loosely translated this will tell the process "User has disconnected. Please end yourself in a proper way'. Most programs which receive this signal will save files, close databases etc. If that fails use kill -15 or kill -9 (-15 is terminate to the process. Like -1 but more insistent. -15 is not sent to the process but to the OS. It is a 'kill with prejeduce' command which might leave a mess. – Hennes Aug 1 '12 at 13:48
  • thanks but i meant automatically. – boby lapointe Aug 1 '12 at 14:32
  • You probably can't do this automatically. The dropped [WiFi] connection should already have caused the shell on the other and to signal all processes with SIGHUP before terminating itself. – Hennes Aug 1 '12 at 14:55

If you are using ssh with an unreliable connection, you may want to give mosh a try: http://mosh.mit.edu/

Mosh was exactly written for this purpose. Note that you need it installed on both sides.


ssh -t Seems to work as I wanted.

  • Care to elaborate? – aefxx Aug 14 '14 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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