杀死给定用户的所有进程 [英] Kill all processes for a given user

查看:153
本文介绍了杀死给定用户的所有进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在一种可靠的方法来杀死给定用户的所有进程? 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆