D
D
DimiDr0lik2015-07-10 11:42:30
linux
DimiDr0lik, 2015-07-10 11:42:30

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

3 answer(s)
S
Saboteur, 2015-07-10
@DimiDr0lik

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

M
Max, 2015-07-10
@MaxDukov

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.

H
He11ion, 2015-07-10
@He11ion

supervisord to help you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question