📅  最后修改于: 2022-03-11 14:59:04.587000             🧑  作者: Mango
#!/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}