杀死给定用户的所有进程 [英] Kill all processes for a given user
问题描述
是否存在一种可靠的方法来杀死给定用户的所有进程? kill(-1, SIGKILL)
,因为该用户将继续工作,除非该用户的流氓进程首先杀死了该杀死进程.到目前为止,我能找到的最好的办法是为该用户遍历system("ps -u")
并以这种方式终止进程,但这似乎确实很麻烦而且效率低下.
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.
为澄清起见,我专门要求一种与POSIX兼容的解决方案.出于某种原因,我认为标记问题posix会将其放在标题中.
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.
推荐答案
只是(暂时)杀死了我的Macbook,
Just (temporarily) killed my Macbook with
killall -u pu -m .
其中pu是我的用户名.注意命令末尾的点.
where pu is my userid. Watch the dot at the end of the command.
也尝试
pkill -u pu
或
ps -o pid -u pu | xargs kill -1
这篇关于杀死给定用户的所有进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!