Re: [CentOS] Any one have a good example...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On 8/29/06, mike.redan@xxxxxxx <mike.redan@xxxxxxx> wrote:
Something like this works alright:


# Check if process is running already
SCRIPT_NAME=do_stuff
pidfile=/tmp/$SCRIPT_NAME.pid


if [ -f $pidfile ]; then
  runpid=`cat $pidfile`
  if ps -p $runpid; then
     echo "$SCRIPT_NAME is already running ... stopping"
     exit 1
  else
     echo "$SCRIPT_NAME pid found but process dead, cleaning up and
starting ..."
     rm -f $pidfile
  fi
else
  echo "No $SCRIPT_NAME Process Detected ... starting"
fi

echo $$ > $pidfile

As long as you don't have multiple scripts starting at approximately
the same time.   I use this same algorithm sometimes but I always use
flock() because otherwise there is a race condition.  Even using
flock() does not remove the race on the creation of the file, though,
which is why if you really want to remove the race condition you make
sure the file pre-existant (via package delivery or something to that
affect).

At least this is how I understand the problem....james
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux