Is there a reliable way to kill all the processes of a given user? kill(-1, SIGKILL)
as that user will work, unless a rogue process of that user kills the killing process first. The best I can find so far is to loop through system("ps -u")
for that user and kill the processes that way, but that seems really hacky and inefficient.
有没有一种可靠的方法可以杀死给定用户的所有进程?杀死(-1,SIGKILL),因为该用户将工作,除非该用户的一个流氓进程首先杀死该杀死进程。到目前为止,我所能找到的最好的方法是为该用户循环系统(“ps -u”),并以这种方式终止进程,但这似乎真的很繁琐和低效。
EDIT: To clarify, I'm specifically asking for a POSIX-compatable solution. For some reason I thought tagging the question posix would put that in the title.
编辑:为了澄清,我特别要求一个posix可压缩的解决方案。出于某种原因,我认为给问题加上标签posix会把它放在标题中。
5 个解决方案
#1
74
Just (temporarily) killed my Macbook with
只是(暂时)扼杀了我的Macbook
killall -u pu -m .
where pu is my userid. Watch the dot at the end of the command.
而pu是我的用户id。注意命令末尾的点。
Also try
也试着
pkill -u pu
or
或
ps -o pid -u pu | xargs kill -1
#2
32
Here is a one liner that does this, just replace username with the username you want to kill things for. Don't even think on putting root there!
这是一行代码,用你想要删除的用户名替换用户名。连根都不要想!
pkill -9 -u `id -u username`
Note: if you want to be nice remove -9, but it will not kill all kinds of processes.
注意:如果您想删除-9,但是它不会杀死所有类型的进程。
#3
5
On Debian LINUX, I use: ps -o pid= -u username | xargs sudo kill -9
.
在Debian LINUX上,我使用:ps -o pid= -u用户名| xargs sudo kill -9。
With -o pid=
the ps header is supressed, and the output is only the pid list. As far as I know, Debian shell is POSIX compliant.
使用-o pid= ps头被压缩,输出仅为pid列表。据我所知,Debian shell是POSIX兼容的。
#4
1
What about iterating on the /proc virtual file system ? http://linux.die.net/man/5/proc ?
在/proc虚拟文件系统上迭代怎么样?http://linux.die.net/man/5/proc ?
#5
1
The following kills all the processes created by this user:
以下内容将删除用户创建的所有进程:
kill -9 -1
#1
74
Just (temporarily) killed my Macbook with
只是(暂时)扼杀了我的Macbook
killall -u pu -m .
where pu is my userid. Watch the dot at the end of the command.
而pu是我的用户id。注意命令末尾的点。
Also try
也试着
pkill -u pu
or
或
ps -o pid -u pu | xargs kill -1
#2
32
Here is a one liner that does this, just replace username with the username you want to kill things for. Don't even think on putting root there!
这是一行代码,用你想要删除的用户名替换用户名。连根都不要想!
pkill -9 -u `id -u username`
Note: if you want to be nice remove -9, but it will not kill all kinds of processes.
注意:如果您想删除-9,但是它不会杀死所有类型的进程。
#3
5
On Debian LINUX, I use: ps -o pid= -u username | xargs sudo kill -9
.
在Debian LINUX上,我使用:ps -o pid= -u用户名| xargs sudo kill -9。
With -o pid=
the ps header is supressed, and the output is only the pid list. As far as I know, Debian shell is POSIX compliant.
使用-o pid= ps头被压缩,输出仅为pid列表。据我所知,Debian shell是POSIX兼容的。
#4
1
What about iterating on the /proc virtual file system ? http://linux.die.net/man/5/proc ?
在/proc虚拟文件系统上迭代怎么样?http://linux.die.net/man/5/proc ?
#5
1
The following kills all the processes created by this user:
以下内容将删除用户创建的所有进程:
kill -9 -1