Thanks to http://tasos.pavta.com
Let’s assume that you are connected to a server via ssh and for some reason you get disconnected. Then most probably you will be left with an idle user session on the server.
w command can tell you in linux about who is connected to the server. And you can easily see here in the idle collumn that there is one idle session from the user ‘tasos’.
root@srv1 [~]# w 11:55:34 up 5 days, 15:12, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT tasos pts/0 18.104.22.168.dsl 11:08 29:23 0.01s 0.09s sshd: tasos tasos pts/1 22.214.171.124.ds 11:40 0.00s 0.03s 0.07s sshd: tasos
There are many ways to kill such a session. Below i will show you one of them.
pstree -p and try to find something like this…
pstree -p command we have to find the parrent pid for the dead session (ssh in our example) . So after we find something like the example above we have to kill -1 the parent pid.
In our example you can see that there is one common process, sshd(32560) with two branches for the two users being connected (1 is me, the current user and the other is the user with the dead session which happens to be me again).
The solution is to kill the branch with the dead user…In our example this would be sshd(28407)….so simply do a
kill-1 28407 and then with the
w command you can see that there is only one user connectd…you!
skill -KILL -v pts/0
$ ps -ft pts/2 11236 $ kill -9 11236