Answers for "bash check other instances"

0

bash check other instances

#!/bin/bash

BNAME=$(basename $0)
LOCKFILE=/var/lock/$BNAME
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
    echo "already running"
    exit
fi

# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}

# do stuff
sleep 1000

rm -f ${LOCKFILE}
Posted by: Guest on July-24-2021

Browse Popular Code Answers by Language