Answer the question
In order to leave comments, you need to log in
How to run a script if the process has terminated?
there is a small script for taking screenshots from the camera, but it sometimes crashes, how to check if it is running and if not, then run it? need on bash
Answer the question
In order to leave comments, you need to log in
A reliable linux-way way is to create a flag in the form of a file that contains the PID of the process. And then track its status. You can simply set it to run every xx minutes via cron.
FLAGFILE=/tmp/myprocess.flg
if [ -e $FLAGFILE ]; then
read <$FLAGFILE PID
ps $PID >> /dev/null
if [ $? –eq0]; then
echo "Process is already running. Exiting."
exit 1
else
echo "Previous shutdown was incorrect. Continue."
rm $FLAGFILE
fi
fi
echo "$$" > $FLAGFILE
# YOUR SCRIPT HERE
rm $FLAGFILE
see the list of processes - command ps
filter the list - grep
in the same way by checking the output of ps -e | grep [process/script name], you can see if it's running.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question