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

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