编写脚本,实现同一个脚本多次运行,系统中只有一个进程

root@nfs scripts]#cat pid.sh

#!/bin/shpidpath=/tmp/a.pidif [ -f "$pidpath" ]  then    kill `cat $pidpath` >/dev/null 2>&1    rm -f $pidpathfiecho $$ >$pidpathsleep 300

测试如下

root@nfs scripts]# ps -ef|grep pid.sh|grep -v grep

[root@nfs scripts]# sh pid.sh &

[1] 3883

[root@nfs scripts]# ps -ef|grep pid.sh|grep -v grep

root       3883   1297  0 20:36 pts/0    00:00:00 sh pid.sh

[root@nfs scripts]# sh pid.sh &

[2] 3890

[root@nfs scripts]# sh pid.sh &

[3] 3894

[1]   Terminated              sh pid.sh

[root@nfs scripts]# sh pid.sh &

[4] 3898

[2]   Terminated              sh pid.sh

[root@nfs scripts]# ps -ef|grep pid.sh|grep -v grep

root       3898   1297  0 20:36 pts/0    00:00:00 sh pid.sh

[3]-  Terminated              sh pid.sh