Kill ssh session and/or stuck processes

2

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?

boby lapointe

Posted 2012-07-31T14:46:28.400

Reputation: 203

Answers

0

ssh -t Seems to work as I wanted.

boby lapointe

Posted 2012-07-31T14:46:28.400

Reputation: 203

Care to elaborate? – aefxx – 2014-08-14T08:46:51.900

4

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.

Hennes

Posted 2012-07-31T14:46:28.400

Reputation: 60 739

I also use screen in such situations as well. Good answer. +1. – Michał Šrajer – 2012-07-31T14:57:07.013

Can you tell me how to kill the leftover processes? – boby lapointe – 2012-08-01T13:42:25.463

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 – 2012-08-01T13:48:57.197

thanks but i meant automatically. – boby lapointe – 2012-08-01T14:32:02.127

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 – 2012-08-01T14:55:10.750

1

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.

hennr

Posted 2012-07-31T14:46:28.400

Reputation: 334