note 103789 deleted from function.posix-getpgid by danbrown

From: Date: Wed, 04 May 2011 17:00:39 +0000
Subject: note 103789 deleted from function.posix-getpgid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179425@lists.php.net to get a copy of this message
Note Submitter: Robert Mays Jr ---- This function and posix_getsid can be used to check if a process is alive (since they return FALSE if the process can not be found) So if you have a PID in a lock file, and you want to know if that process is still running- you can use this code: <?php $lockfile = sys_get_temp_dir() . '/myScript.lock'; $pid = file_get_contents($lockfile); if (posix_getsid($pid) === false) { print "process has died! restarting...\n"; file_put_contents($lockfile, getmypid()); // create lockfile } else { print "PID is still alive! can not run twice!\n"; exit; } ?> :-) perfect if you need to make sure a cron job or shell script has ended before it can be started again.

« previous php.notes (#179425) next »