有趣的事

如何同时只能运行一个SHELL

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

解释:

kill -0 pid 不发送任何信号,但系统会进行错误检查。

所以经常用来检查一个进程是否存在,存在返回0;不存在返回1

man手册里:

The signals listed below may be available for use with kill. When known constant, numbers and default behavior are shown.

Name Num Action Description

0 0 n/a exit code indicates if a signal may be sent

相关阅读