note 103789 modified in function.posix-getpgid by danbrown

From: Date: Wed, 04 May 2011 15:46:19 +0000
Subject: note 103789 modified in function.posix-getpgid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179417@lists.php.net to get a copy of this message
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. --was-- 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: $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. http://php.net/manual/en/function.posix-getpgid.php

« previous php.notes (#179417) next »