今天工作中遇到了同事的终端登陆不上去的问题,尝试着如何解决,首先想到的就是先干掉tty终端。
下面是总结的如何杀掉tty终端:
1.使用w命令查看当前登陆的用户及使用的tty
[root@host ~]# w -s
10:16:19 up 12 days, 23:47, 25 users, load average: 6.71, 10.24, 12.16
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 :4 Thu08 4days 0.08s 0.08s bash
eric pts/1 :6 18Jul18 11days 0.03s 0.03s /bin/bash
evan pts/2 :11 Wed13 4days 25:43 25.22s /usr/libexec/gn
wang pts/3 :22 24Jul18 6days 1:13m 2.31s /usr/libexec/gn
mark pts/5 :9 09:57 19:15 3:22 2:57 /usr/bin/java -
john pts/6 :14 Thu16 3days 16:48m 11:09 /bin/java -Dosg
2.用ps -t 命令可以得到终端的进程号
[root@host system]# ps -t /dev/pts/2
PID TTY TIME CMD
15272 pts/2 00:00:00 bash
16970 pts/2 00:00:00 eclipse
16971 pts/2 00:26:00 java
3、用kill -9命令
可以将进程杀掉,以关闭终端。前提:kill命令的执行者必须是超级用户或对tty1的进程有操作权限,否则,命令会报错:Operation not permitted,如:
[root@host ~]# kill -9 15272
[root@host ~]# ps -t /dev/pts/2
PID TTY TIME CMD
9565 pts/2 00:00:00 bash
[root@host ~]# kill -9 15272
[root@host ~]# ps -t /dev/pts/2
error: TTY could not be found
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).