Shell – How to terminate a hung process in SSH

shellssh

I have a SSH session with a VM running on Amazon AWS.

One of the programs I had run hung up and froze the SSH terminal.

So I hit Enter+~+.

Now when I am trying to connect to my machine it says connection timed out.

  1. Does this mean that connection was only terminated from the client
    side and is still active on server? If so how do I create a new
    connection?
  2. Ctrl+C does not work on a SSH shell. Does this mean it is not
    possible to terminate the hung up command without terminating the
    SSH session?

Best Answer

You can send a SIGSTOP to the process (most shells use Ctrl-Z for this), which will tell the present process pause it's current state. This should then return you to your shell command prompt. You can then see what jobs are paused with the jobs command and then kill the process with the kill command. If the process is number 1 in the list of the output of jobs then you would issue kill -TERM %1 (and check it has gone with jobs once more). You may have to send a SIGKILL instead (kill -KILL %1).

A simple guide to job control can be found at:

http://en.wikibooks.org/wiki/A_Quick_Introduction_to_Unix/Job_Control

Related Question