【问题标题】:Linux Bash kill consecutive processesLinux Bash 杀死连续的进程
【发布时间】:2018-03-10 11:57:09
【问题描述】:

我在bash中写了一系列流程

#!/bin/bash
#sample.sh
for filename in ./*
do
./a.out filename
done

然后我使用 nohup 命令运行脚本:

nohup sh sample.sh 2>&1 &

然后我发现 a.out 出了点问题。我正在尝试修改 a.out,首先我需要 kill 进程,但事实证明我一次只能杀死一个。 ./* 目录中有数百个文件。

如何用一个或几个命令杀死它们?

【问题讨论】:

  • ./a.out 没关系,因为您没有在后台运行它,您在后台运行的唯一进程是 sample.sh ,杀死它,停止整个进程

标签: bash kill


【解决方案1】:

执行nohup 命令时会打印pid。像这样与 kill 一起使用:

$ nohup sh sample.sh 2>&1 &
[1] 25062
appending output to nohup.out
$kill 25062
[1]+  Terminated: 15          nohup sh sample.sh 2>&1

或者如果你没有 pid,你可以使用ps -ef | grep sample 来查找它。然后,使用 pid 终止进程。像这样:

$ nohup sh sample.sh 2>&1 &
[1] 25066
appending output to nohup.out
$ ps -ef | grep sample
  501 25066  2768   0 10:48PM ttys001    0:00.01 sh sample.sh
  501 25070  2768   0 10:49PM ttys001    0:00.01 grep sample
$ kill 25066
[1]+  Terminated: 15          nohup sh sample.sh 2>&1
$

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    相关资源
    最近更新 更多