首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

shell sh程序与此同时只能运行一次

2012-09-01 
shell sh程序同时只能运行一次#!/bin/shcheckPid(){pid$$name`basename $0`echo $pid $nameif [ -f ./d.

shell sh程序同时只能运行一次
#!/bin/sh

checkPid(){
  pid=$$
  name=`basename $0`
  echo $pid $name
  if [ -f ./d.pid ]; then
    lastPid=`cat ./d.pid |awk '{print $1}'`
    echo $lastPid
    x=`ps -ef|grep $name |grep -v grep |grep -v awk |awk -v p=$lastPid -v n=$name '{if($2~p && $NF~n){print $0}}' |wc
-l`
    echo $x
    if [ "$x" -eq "1" ]; then
      exit
    fi
  fi
  echo $pid `date` > d.pid


  return 0
}

checkPid

热点排行