Linux Bash 杀死连续的进程
Linux Bash kill consecutive processes
我在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 进程,但事实证明我一次只能杀死一个。 ./*
目录中有数百个文件。
如何用一个或几个命令杀死他们?
执行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
$
我在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 进程,但事实证明我一次只能杀死一个。 ./*
目录中有数百个文件。
如何用一个或几个命令杀死他们?
执行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
$