I want to create a service that monitors the existence of a certain process. I wrote the following shell script:
#!/bin/sh while : do w=`ps u -A | grep -P ".+Sl.+/usr/local/MySource/endpoint" -c` sleep 10 if [ $w -lt 2 ] then echo 0 > /sys/class/leds/alix\:2/brightness killall -9 /usr/local/MySource/endpoint nohup /usr/local/MySource/endpoint &> /dev/null & last_endpoint_m=`date` echo $last_endpoint_m > /tmp/endpoint_msleep echo $w >> /tmp/endpoint_msleep else echo 1 > /sys/class/leds/alix\:2/brightness fi sleep 10 done
If the process exists, the script will switch off a LED on my machine and start the process. The LED should be
ON while the process is running.
I then run this script by adding the following line to
nohup /usr/local/MyTools/additions/XR50_endpoint_m &> /dev/null &
When I run
ps, I find that the
XR50_endpoint_m & process is there.
My Machine is an ALIX board with limited resources (embedded) running Debian.
The question is:
$w is always zero (I verified this from the output file
/tmp/endpoint_msleep). Although the process exists and the script is working fine if I run it manually (
What do you think the reason is and what is the best way to monitor a process?