今天工做中遇到了同事的終端登錄不上去的問題,嘗試着如何解決,首先想到的就是先幹掉tty終端。java
下面是總結的如何殺掉tty終端:bash
1.使用w命令查看當前登錄的用戶及使用的ttyeclipse
[root@host ~]# w -s3d
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 WHATip
root pts/0 :4 Thu08 4days 0.08s 0.08s bashit
eric pts/1 :6 18Jul18 11days 0.03s 0.03s /bin/bashio
evan pts/2 :11 Wed13 4days 25:43 25.22s /usr/libexec/gnclass
wang pts/3 :22 24Jul18 6days 1:13m 2.31s /usr/libexec/gnthread
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
三、用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).