如何使Shell脚本只有一个实例在运行

来源:互联网 发布:电气控制仿真设计软件 编辑:程序博客网 时间:2024/06/16 07:56
LOCKFILE=/tmp/lock.txtif [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then    echo "already running"    exitfi# make sure the lockfile is removed when we exit and then claim ittrap "rm -f ${LOCKFILE}; exit" INT TERM EXITecho $$ > ${LOCKFILE}################## your stuff here#################rm -f ${LOCKFILE}

感谢这篇文章

0 0
原创粉丝点击