Think before you speak, read before you think.

使用pkill踢掉linux用户

by

in

先看看都哪些终端登陆

root@ibm:~# w
19:28:23 up 2 days, 12:12, 1 user, load average: 0.20, 0.29, 0.33
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.1.102 19:12 1.00s 1.24s 0.02s w

用户帐号/所用的终端/何处登陆/登陆时间/空闲时间/耗费的CPU/执行后耗费CPU/正在执行

root pts/0 192.168.1.102 19:12 1.00s 1.24s 0.02s w

上面可以看到只有我一个用户,使用如下命令会将我自己踢出:

pkill -kill -t pts/0

进而衍生出对pkill用法的整理

pkill is used to send signals to Process (computing)processes. The pkill command allows the use of extended regular expression patterns and other matching criteria.

pkill的使用是发送信号给进程,支持扩展正则表达式或其他匹配规则.

pgrep, pkill – look up or signal processes based on name and other attributes。

后面跟进程名而kill只能跟进程号,pkill还支持自动补全

那么,如果说xxx有两个进程

root     10976     1  0 Jul31 ?        00:00:00 xxx: master process usr/local/xxx/sbin/xxx
www-data 10978 10976  0 Jul31 ?        00:00:00 xxx: worker process

运行pkill xxx 会把他们全杀死,有时我们并不想要这样的结果,所以要认准了再用。


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *