【问题标题】:killing series of processes杀死一系列进程
【发布时间】:2010-12-13 02:05:43
【问题描述】:

当我输入命令 ps -ef |grep sharatds 时,我会得到一个进程列表。

sharatds 13164 13163  0 20:53 pts/2    00:00:00 [bt.C.256] <defunct>
sharatds 13165 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13199 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13233 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13267 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13301 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13335 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13369 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13403 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13437 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13471 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13505 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13539 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13573 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13607 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13641 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13675 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13709 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13743 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13777 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13811 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13845 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13879 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>
sharatds 13913 13163  0 20:53 pts/2    00:00:00 [rsh] <defunct>

我想杀死所有最后一列已失效的进程。

谁能帮我写一个脚本?

【问题讨论】:

  • 如果可以,最好避免使用 grepping ps。如果可用,请使用pgrep -upkill -u,如果不可用,请使用ps -u。使用grep 存在误报的风险。布兰登是正确的。他们已经死了。

标签: bash awk kill


【解决方案1】:

这样就可以了:

ps -ef | grep sharatds | awk '{print $2}' | xargs kill

【讨论】:

    【解决方案2】:

    我通常会这样做:

    kill $(ps -ef |grep sharatds|awk '{print $2}')
    

    编辑:等等!这些是已失效的进程。他们已经死了,不能再杀了!父进程必须运行wait() 来读取它们的状态,以便清理它们并将它们从进程表中删除。

    【讨论】:

    • 我真的很喜欢这种方法,很高兴注意到如果你想在常规杀死不起作用的情况下“超级杀死”它,你也可以使用sudo kill -9 $(ps -ef | grep sharatds | awk '{print $2}')。 (不过不适合胆小的人)大声笑
    • 或者杀死父进程。当父节点死亡时,子节点由 init(进程 1)继承,它会自动收割僵尸子节点。
    猜你喜欢
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多