編寫腳本,實作同一個腳本多次運作,系統中隻有一個程序
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