Skip to main content

How to kill the tty sessions in unix

How to kill the tty sessions in UNIX


1. First you have to check how many logins are present in server.  Use "w" command to list all the sessions.

[root@testserver ~]# w
 00:22:13 up 106 days, 22:41,  2 users,  load average: 3.31, 1.53, 1.09
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/15   master.world.com 00:22    1.00s  0.64s  0.61s w
root     pts/18   10.47.18.111     09Mar14  36days  0.01s  0.01s -bash



Total 2 users are logged in. See there is a session from the IP 10.47.18.111 is idle for last 36 days.  And I want to end this session.  For that we have to note down the tty id which is used for this Login. See here it is pts/18

2.  Now you have to find out what is the process id of this particular tty session - pts/18 . "ps -ft" is using for this purpose. 

[root@testserver ~]# ps -ft pts/18
UID        PID  PPID  C STIME TTY          TIME CMD
root      9886  9882  0 Mar09 pts/18   00:00:00 -bash


3. Now you have to kill this process. Here our process id is 9886. 

[root@testserver ~]# kill -9 9886

4. Now check the available tty sessions again.

[root@testgfs2 ~]# w
 00:42:32 up 106 days, 23:02,  1 user,  load average: 0.90, 1.14, 1.29
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/15   master.world.com  00:22    0.00s  0.60s  0.56s w


See here only one user is logged in. That means the session which was idle is closed. 

Comments

Post a Comment