Chinaunix首页 | 论坛 | 博客
  • 博客访问: 537862
  • 博文数量: 119
  • 博客积分: 3167
  • 博客等级: 中校
  • 技术积分: 1215
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-20 21:21
文章分类

全部博文(119)

文章存档

2015年(21)

2012年(4)

2011年(1)

2007年(11)

2006年(50)

2005年(32)

分类: LINUX

2006-01-18 03:40:04

#!/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
阅读(1554) | 评论(1) | 转发(0) |
0

上一篇:articles

下一篇:使用getopts获取命令行参数

给主人留下些什么吧!~~