简体   繁体   English

如何杀死一个进程?

[英]How to kill a process except one?

I have few processes starting with string apple. 我有几个以苹果字符串开头的进程。 So my processes names are apple1, apple2, apple3 till apple10. 所以我的进程名称是apple1,apple2,apple3直到apple10。 Now I use command "pkill -f apple". 现在,我使用命令“ pkill -f apple”。 But it kills all processes starting with apple. 但是它杀死了所有从苹果开始的进程。 I want apple2 not to get killed with the above command. 我希望apple2不会被上述命令杀死。 So can someone tell me how the above command can be modified? 那么有人可以告诉我如何修改上面的命令吗?

This works for excluding the apple2 pid from the list and kill others , Not sure if your problem will be solved with this. 这适用于从列表中排除apple2 pid并杀死其他pid,不确定是否可以用此方法解决您的问题。

ps -aef | grep apple | grep -v apple2 | awk '{print $2}'|while read pid
do
kill -9 $pid
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM