linux shell 杀掉所有包含某名称的进程

In bash, you should be able to do:

kill $(ps aux | grep '[p]ython csp_build.py' | awk '{print $2}')
其中
'[p]ython csp_build.py'是要查询进程的指令。

Details on its workings are as follows:

  • The ps gives you the list of all the processes.
  • (//ps列出所有的进程列表)
  • The grep filters that based on your search string, [p] is a trick to stop you picking up the actualgrep process itself.
  • //意译:grep是一个管道命令,其数据来源是依托之前的ps的数据。[p]是为了严格控制字符串从[p]开始,是为了防止杀掉grep本身。
  • The awk just gives you the second field of each line, which is the PID.
  • //译:awk则是列出grep指令执行结果的第二列,也就是pid.
  • The $(x) construct means to execute x then take its output and put it on the command line. The output of that ps pipeline inside that construct above is the list of process IDs so you end up with a command like kill 1234 1122 7654.
  • //译:$(x)结构意味着要执行指令x,然后输出,并把它放在指令(command)行中。上述指令包含的ps管道指令的输出就是进程ID列表。所以你可以使用kill这种指令来杀掉他们。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值