# problem with  old consoles



## bsdfunn (Jun 16, 2013)

Hello

I have some troubles with old console sessions (after closed or crashed SSH connections, they don't expire). How i can can *I* kill/clear idle TTYs?

```
w
8:35PM  up 154 days, 22:05, 8 users, load averages: 0.53, 0.62, 0.65
USER   TTY      FROM                      LOGIN@  IDLE WHAT
mark   pts/0    192.168.1.1               11Apr13 61days -
root   v0       -                         22May13 25days /usr/libexec/getty Pc ttyv0
nick   pts/1    10.10.10.1                7:04PM     - w
nick   pts/0    10.10.10.1                11Apr13 61days -
nick   pts/0    10.10.10.1                16Apr13 61days -
nick   pts/1    10.10.10.1                22May13     - w
mark   pts/1    172.17.150.1              02Jun13     - w
nick   pts/1    10.10.10.1                03Jun13     - w
```


----------



## cpm@ (Jun 16, 2013)

Try killing the sshd(8) process. Run `% ps x | grep sshd` and kill(1) all expired connection/s.


----------



## phoenix (Jun 17, 2013)

cpu82 said:
			
		

> Try killing the sshd(8) process. Run `% ps x | grep sshd` and kill(1) them.



Note:  pgrep(1) and pkill(1) can simplify things.


----------



## cpm@ (Jun 17, 2013)

phoenix said:
			
		

> Note:  pgrep(1) and pkill(1) can simplify things.



Yes, good shot


----------



## bsdfunn (Jun 17, 2013)

```
ps x | grep sshd
65074 ??  Is        0:00.00 /usr/sbin/sshd
68564 ??  Ss        0:00.01 sshd: nick@pts/1 (sshd)
68601  1  S+        0:00.00 grep sshd
```

But `w`/`who` show idle console connections.


----------



## cpm@ (Jun 17, 2013)

bsdfunn said:
			
		

> But w /who show idle console connections.



Yes, but not show the process ID (PID). Read ps(1)() man page.


> As in certain cults it is possible to kill a process if you know its true name.
> -- Ken Thompson and Dennis M. Ritchie.


----------



## bsdfunn (Jun 17, 2013)

This is my current *SSH* connection.

```
68564 ??  Ss  0:00.01 sshd: nick@pts/1 (sshd)
```


----------



## bsdfunn (Jun 20, 2013)

Anyone*?*


----------



## cpm@ (Jun 20, 2013)

Or if you prefer, run `% fstat /dev/pts/[num]` and then, use the PIDs that you get from fstat(1)() to kill the connection/s.

E.g.

```
[CMD]% fstat /dev/pts/0[/CMD]
USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W NAME
charly   csh        72927 ctty /dev        148 crw--w----   pts/0 rw  /dev/pts/0
charly   csh        72927   15 /dev        148 crw--w----   pts/0 rw  /dev/pts/0
charly   csh        72927   16 /dev        148 crw--w----   pts/0 rw  /dev/pts/0
charly   csh        72927   17 /dev        148 crw--w----   pts/0 rw  /dev/pts/0
charly   csh        72927   18 /dev        148 crw--w----   pts/0 rw  /dev/pts/0
charly   csh        72927   19 /dev        148 crw--w----   pts/0 rw  /dev/pts/0
charly   mate-terminal 72925   16 /dev        148 crw--w----   pts/0 rw  /dev/pts/0
```


----------

