在 Solaris 10 服务器上,如果我执行 a w
,我会得到以下信息:
12:26pm up 85 day(s), 1:13, 6 users, load average: 0.38, 0.36, 0.38
User tty login@ idle JCPU PCPU what
blah pts/1 3Aug15 2days 632:47 632:47 -bash
root pts/2 4Sep15 6days 201:05 77:59 -bash
blah pts/3 3Aug15 2days 72:40 -bash
blah pts/6 13Jul1560days 3:24 -bash
root pts/22 12:10pm bash
root pts/23 12:17pm -bash
当我这样做时who -all
,我得到
. system boot Jun 18 11:13
. run-level 3 Jun 18 11:14 3 0 S
LOGIN console Jul 12 13:54 . 4681
zsmon . Jun 18 11:15 old 404
LOGIN console Jun 18 11:15 . 876 id= dt term=0 exit=1 (:0)
ostor + pts/1 Aug 3 10:35 old 29213 ()
init.css . Jun 18 11:16 old 1331 id= h1
root + pts/2 Sep 4 08:32 old 13085 ()
ostor + pts/3 Aug 3 10:41 old 29867 ()
roxa pts/4 Sep 9 08:45 old 4082 id=ts/4 term=0 exit=0
roxa pts/5 Sep 9 09:26 old 4369 id=ts/5 term=0 exit=0
ostor + pts/6 Jul 13 07:45 old 26750 ()
roxa pts/7 Sep 9 09:28 old 9010 id=ts/7 term=0 exit=0
roxa pts/8 Sep 9 10:11 old 9242 id=ts/8 term=0 exit=0
roxa pts/9 Sep 9 10:59 old 16138 id=ts/9 term=0 exit=0
roxa pts/10 Sep 9 11:01 old 21040 id=s/10 term=0 exit=0
roxa pts/11 Sep 9 11:02 old 21238 id=s/11 term=0 exit=0
roxa pts/12 Sep 9 11:19 old 21514 id=s/12 term=0 exit=0
ostor pts/13 Sep 9 14:29 old 14367 id=s/13 term=0 exit=0
ostor pts/14 Sep 9 14:58 old 14548 id=s/14 term=0 exit=0
roxa pts/15 Sep 10 08:28 old 13820 id=s/15 term=0 exit=0
roxa pts/16 Sep 10 10:16 old 14340 id=s/16 term=0 exit=0
roxa pts/17 Sep 10 08:40 old 15219 id=s/17 term=0 exit=0
roxa pts/18 Sep 10 16:51 20:07 17179 id=s/18 term=0 exit=0
roxa pts/19 Sep 10 16:59 19:58 18319 id=s/19 term=0 exit=0
roxa pts/20 Sep 11 08:59 3:54 2313 id=s/20 term=0 exit=0
roxa pts/21 Sep 11 11:20 1:32 20981 id=s/21 term=0 exit=0
root + pts/22 Sep 11 12:10 . 28241 ()
roxa pts/23 Sep 11 12:49 0:10 2623 id=s/23 term=0 exit=0
roxa pts/24 Sep 11 12:24 0:29 226 id=s/24 term=0 exit=0
如何终止非活动用户 roxa 的所有进程?
答案1
如果你只杀死他的 sshd,也许还有一些进程可以在虚拟终端被破坏后幸存下来。
如果你想要一个干净的方法,你可以通过以下单行杀死他的所有进程:
for i in `ps uxa|grep ^roxa|sed 's/\+//g'|awk '{print $2}'`;do kill -9 $i;done
这个单行脚本的本质是在 `` 之间,一个并不复杂的管道处理你的ps uxa
输出,并从中提取他的 pid。