如何保证sh脚本只有一个进程在运行

#!/usr/bin/sh

LOCKFILE=jihao.lock
if [ -f ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
    echo "filecollector is 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}

 
 
sleep 100
rm -f ${LOCKFILE}
 
BTW: http://stackoverflow.com/ 很好很实用

你可能感兴趣的:(脚本,F#)