Linux Bash杀死连续进程

Linux Bash杀死连续进程,bash,kill,Bash,Kill,我用bash编写了一系列流程,就像 #!/bin/bash #sample.sh for filename in ./* do ./a.out filename done 然后使用nohup命令运行脚本: nohup sh sample.sh 2>&1 & 然后我发现a.out出了问题。我试图修改a.out,首先我需要杀死进程,但结果是一次只能杀死一个进程。/*目录中有数百个文件 如何用一个或几个命令杀死它们?执行nohup命令时会打印pid。将其与kill一起使用,如

我用bash编写了一系列流程,就像

#!/bin/bash
#sample.sh
for filename in ./*
do
./a.out filename
done
然后使用nohup命令运行脚本:

nohup sh sample.sh 2>&1 &
然后我发现a.out出了问题。我试图修改a.out,首先我需要杀死进程,但结果是一次只能杀死一个进程。
/*
目录中有数百个文件


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

执行
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
$

执行
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
$

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