check_procs 已经处理了这种情况。
check_procs 可以区分作为解释器参数启动的脚本与直接运行 hashbang 解释器的作业之间的区别。即使这两个在 ps 输出中看起来都一样!后一种情况将不在check_procs -C python
!
如果您通过 python: 显式运行脚本python <filename.py>
,那么您可以使用check_procs -C python -a filename.py
.
如果您将#!/usr/bin/python
脚本放入并运行它们./filename.py
,那么您可以使用check_procs -C filename.py
.
显示此行为的示例命令行会话:
#make test.py directly executable. See code below
$ chmod a+x test.py
#launch via python explicitly:
$ /usr/bin/python ./test.py &
[1] 27094
$ check_procs -C python && check_procs -C test.py && check_procs -a test.py
PROCS OK: 1 process with command name 'python'
PROCS OK: 0 processes with command name 'test.py'
PROCS OK: 1 process with args 'test.py'
#launch via python implicitly
$ ./test.py &
[2] 27134
$ check_procs -C python && check_procs -C test.py && check_procs -a test.py
PROCS OK: 1 process with command name 'python'
PROCS OK: 1 process with command name 'test.py'
PROCS OK: 2 processes with args 'test.py'
#PS 'COMMAND' output looks the same
$ ps 27094 27134
PID TTY STAT TIME COMMAND
27094 pts/6 S 0:00 /usr/bin/python ./test.py
27134 pts/6 S 0:00 /usr/bin/python ./test.py
#kill the explicit test
$ kill 27094
[1] - terminated /usr/bin/python ./test.py
$ check_procs -C python && check_procs -C test.py && check_procs -a test.py
PROCS OK: 0 processes with command name 'python'
PROCS OK: 1 process with command name 'test.py'
PROCS OK: 1 process with args 'test.py'
#kill the implicit test
$ kill 27134
[2] + terminated ./test.py
$ check_procs -C python && check_procs -C test.py && check_procs -a test.py
PROCS OK: 0 processes with command name 'python'
PROCS OK: 0 processes with command name 'test.py'
PROCS OK: 0 processes with args 'test.py'
test.py 是一个休眠 2 分钟的 Python 脚本。它是 chmod +x 并且有一个 hashbang#!
行调用 /usr/bin/python。
#!/usr/bin/python
import time
time.sleep(120)