crontab problem: multiple processes at the same time
Hi,
I scheduled a job to run a script each two minutes that verifies if a
process (python script) is running or not.
If it's not running, it should start a new process of the same python
script.
The problem is that crond sometimes starts three or more processes
within seconds of each other.
Why does this happen? How to prevent this behavior?
System: Debian Sarge
Here's the data:
$ crontab -l
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=lupe
HOME=/home/lupe
LOGNAME=/home/lupe/scripts/segur.log
#m h dom mon dow
1-59/2 * * * mon-fri /home/lupe/mus/controlador.sh
$ cat controlador.sh
set +v
# get pid of 'gerir.py'
FICHEIRO='gerir.py'
PROGRAMA=$(ps aw | grep $FICHEIRO | grep -v T)
PID=$(echo $PROGRAMA | awk '{ print $1 }')
#echo "PID: " $PID
# still running or halted/suspended?
F='/home/lupe/mus/predefinidos.cfg'
DATA_F=$(ls -l $F | awk '{ print $6 " " $7 }')
DATA_F=$(date +%s --date="$DATA_F")
DATA_ACTUAL=$(date +%s)
let diferenca_segundos=$DATA_ACTUAL-$DATA_F
PRAZO=240 # 4 minutes
if [[ $diferenca_segundos -gt $PRAZO && -n $PID ]]
then # service has to start again
kill -9 $PID
sleep 3
cd /home/lupe/mus/
exec /usr/bin/python /home/lupe/mus/$FICHEIRO &
elif [[ $diferenca_segundos -gt $PRAZO && -z $PID ]]
then
cd /home/lupe/mus/
exec /usr/bin/python /home/lupe/mus/$FICHEIRO &
fi
$ ps auxw | grep python
lupe 4821 0.1 3.3 28480 25956 ? S 00:53 0:03
/usr/bin/python /home/lupe/mus/gerir.py
lupe 5407 0.3 3.3 28492 25976 ? S 01:29 0:01
/usr/bin/python /home/lupe/mus/gerir.py
lupe 5436 0.5 3.3 28472 25916 ? S 01:31 0:01
/usr/bin/python /home/lupe/mus/gerir.py
lupe 5549 1.1 3.3 28468 25912 ? S 01:33 0:00
/usr/bin/python /home/lupe/mus/gerir.py
lupe 5584 0.0 0.0 2048 772 pts/4 R+ 01:34 0:00 grep
python
Previously to posting, I googled and found out that Via chipsets (or
some of them) do set the system clock time forward and backward on a
strange way that could cause this problem. I have Via chipsets on my
motherboard: VT8237 PCI Bridge, VT8374 P4X400 Host Controller, and
others. Any further ideas on this?
Luis P. Mendes
Reply to: