我
[pgrep](http://en.wikipedia.org/wiki/Pgrep)会这样做(注意,未经测试的代码):
exec("pgrep lighttpd", $pids);if(empty($pids)) { // lighttpd is not running!}我有一个执行类似操作的bash脚本(但使用SSH隧道):
#!/bin/shMYSQL_TUNNEL="ssh -f -N -L 33060:127.0.0.1:3306 tunnel@db"RSYNC_TUNNEL="ssh -f -N -L 8730:127.0.0.1:873 tunnel@db"# MYSQLif [ -z `pgrep -f -x "$MYSQL_TUNNEL"` ] then echo Creating tunnel for MySQL. $MYSQL_TUNNELfi# RSYNCif [ -z `pgrep -f -x "$RSYNC_TUNNEL"` ]then echo Creating tunnel for rsync. $RSYNC_TUNNELfi
您可以使用要监视的命令来更改此脚本。



