note 95303 added to function.getmypid

From: Date: Fri, 25 Dec 2009 09:50:01 +0000
Subject: note 95303 added to function.getmypid
Groups: php.notes 
Request: Send a blank email to php-notes+get-164321@lists.php.net to get a copy of this message
The 'ps' command has an option that can make filtering for a specific process more efficient. Using this the work of looking for matching processes can be made neater: <?php /* Return an array of the pids of the processes that are running for the specific command e.g. returnPids('myprocess.php'); */ function returnPids($command) { exec("ps -C $command -o pid=",$pids); foreach ($pids as $key=>$value) $pids[$key]=trim($value); return $pids; } /* Returns an array of the pids for processes that are like me, i.e. my program running */ function returnMyPids() { return returnPids(basename($_SERVER["SCRIPT_NAME"])); } ?> e.g. to bomb out if I'm running already if (count(returnMyPids())>1) exit; ---- Server IP: 69.147.83.197 Probable Submitter: 80.5.46.222 ---- Manual Page -- http://www.php.net/manual/en/function.getmypid.php Edit -- https://master.php.net/note/edit/95303 Del: integrated -- https://master.php.net/note/delete/95303/integrated Del: useless -- https://master.php.net/note/delete/95303/useless Del: bad code -- https://master.php.net/note/delete/95303/bad+code Del: spam -- https://master.php.net/note/delete/95303/spam Del: non-english -- https://master.php.net/note/delete/95303/non-english Del: in docs -- https://master.php.net/note/delete/95303/in+docs Del: other reasons-- https://master.php.net/note/delete/95303 Reject -- https://master.php.net/note/reject/95303 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164321) next »