私はプロセスをチェックする方法は、Pythonで実行しています(Linuxで)?
l = commands.getstatusoutput("ps aux |grep 'python2.7'| grep
'test.py' | grep -v 'grep' | wc -l")
if int(l[1]) == 1:
pid = commands.getstatusoutput("ps -ef |grep 'python2.7'| grep 'test.py ' |awk '{print $2}'")
print "the process 'test.py ' have running ,the pid is :"+str(pid[1])
sys.exit(0)
else:
print "not running"
出力終了し、その後、プロセスは、プロセス名(test.py)に基づいて実行されているかどうかを確認しようとしています:その後、私は
$ ps aux | grep agg_test
georgetovrea 25181 0.0 0.0 10944 932 pts/9 S+ 23:26 0:00 grep --color=auto test
をチェックしよう
[email protected]:/test$ python2.7 test.py
the process 'test.py ' have running ,the pid is :26517
26542
を
プロセスが実行されていない、プロセス(test.py)が実行されていることを確認して終了して終了します。 が表示されますが、常にプロセスが実行中です。
プロセスの実行状態を確認するにはどうすればよいですか?助言がありますか?助けてくれてありがとう。
がコマンドで使用します」あなたがシェルでそのコマンドを実行した場合とは違う何かを報告しているPython内から実行していますか? –
ニック、test.pyを実行すると、 "プロセス 'test.py'が実行中です.pidは次のとおりです:26517 26542" – georgetovrea
[this](https://stackoverflow.com/questions/568271)の可能な複製/ pid-in-pythonで-a-process-with-a--a-process-with-there-exist-a-processが存在するかどうかを調べる)。 – IsaacS