文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>shell脚本同一时间只能有一个在运行

shell脚本同一时间只能有一个在运行

时间:2006-01-18  来源:ruiqingzheng

#!/bin/bash

me=`basename $0`
pidfile=/var/run/$me.pid

mycode()
{
        touch $pidfile
        echo $$ > $pidfile
        sleep 10
}
myexit()
{
        rm -f $pidfile
        exit 0
}

trap 'myexit'  2

if test -e $pidfile
then
        kill -0 `cat $pidfile` >/dev/null 2>&1
        if [ $? -eq 0 ]; then
                echo "Another instance is running , `cat $pidfile`"
                exit 1
        else
                rm -f $pidfile
                mycode
        fi
else
        mycode
fi

myexit
相关阅读 更多 +
排行榜 更多 +
挖掘机卡车

挖掘机卡车

模拟经营 下载
我的汤姆猫小米版

我的汤姆猫小米版

模拟经营 下载
我的小小邮轮

我的小小邮轮

模拟经营 下载