Check if a Python job is running using PHP -
i've got python script thats called twice day via cron job trigger alarm runs in loop, , terminated pressing physical button , calling destroy function when button pressed.
so far good.
now, i'd check via php if script running - before button pressed after it's called via cron.
how can this?
based on question - i've tried following:
exec("jobs", $pids); if(!empty($pids)) { print_r($pids); }
but doesn't seem returning value. calling jobs
terminal works expected , lists job running when invoking script directly using python3 alarm.py &
.
using exec("ps -a | grep -i $processname | grep -v grep", $pids);
feel won't work since process id can change , can not known until script running.
use pgrep
this:
pgrep -f 'python scriptname.py ...'
-f
can used specify full command line of python process avoid collision multiple python processes running in parallel.
Comments
Post a Comment