check_procs已經處理這種情況。
check_procs可以告訴推出作爲參數來解釋腳本之間的差異VS作業直接運行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是一種Python腳本,睡2分鐘。它是chmod + x並且有一個hashbang #!
行調用/ usr/bin/python。
#!/usr/bin/python
import time
time.sleep(120)
您想使用shell來啓動一個Python腳本,該腳本又將啓動另一個進程。但是,您希望shell使用不同的進程名稱和參數來啓動原始Python進程,而這些進程與實際提供給shell的參數相同。那是對的嗎? –
是的..這正是我想要達到的! –
check_procs比看ps命令輸出更聰明。如果您使用#,它已經可以檢測到該名稱!在你的python中直接執行它們。 [完全沒有在手冊頁:(記載見我的回答:http://stackoverflow.com/a/10232406/117714 – spazm