编写脚本,实现同一个脚本多次运行,系统中只有一个进程
root@nfs scripts]#cat pid.sh
#!/bin/sh
pidpath=/tmp/a.pid
if [ -f "$pidpath" ]
then
kill `cat $pidpath` >/dev/null 2>&1
rm -f $pidpath
fi
echo $$ >$pidpath
sleep 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
[2] 3890
[3] 3894
[1] Terminated sh pid.sh
[4] 3898
[2] Terminated sh pid.sh