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 executex
then take its output and put it on the command line. The output of thatps
pipeline inside that construct above is the list of process IDs so you end up with a command likekill 1234 1122 7654
. - //译:$(x)结构意味着要执行指令x,然后输出,并把它放在指令(command)行中。上述指令包含的ps管道指令的输出就是进程ID列表。所以你可以使用kill这种指令来杀掉他们。