如何同时只能运行一个SHELL

2013-12-03 阅读 35
```
pidfile=/path/to/pidfile
if [ -f "$pidfile" ] && kill -0 `cat $pidfile` 2>/dev/null; then
    echo still running
    exit 1
fi  
echo $$ > $pidfile
```

<p>解释:</p>

<p>kill -0 pid 不发送任何信号,但系统会进行错误检查。<br><br>
所以经常用来检查一个进程是否存在,存在返回0;不存在返回1</p>

<p>man手册里:</p>

<p>The signals listed below may be available for use with kill. When known constant, numbers and default behavior are shown.<br><br>
Name Num Action Description<br><br>
0 0 n/a exit code indicates if a signal may be sent</p>
更新于 2023年03月28日