note 59889 modified in function.getmypid by danbrown

From: Date: Sun, 20 Jul 2008 00:26:08 +0000
Subject: note 59889 modified in function.getmypid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141842@lists.php.net to get a copy of this message
<?php /* mixed getpidinfo(mixed pid [, string system_ps_command_options]) this function gets PID-info from system ps command and return it in useful assoc-array, or return false and trigger warning if PID doesn't exists $pidifo=getpidinfo(12345); print_r($pidifo); Array ( [USER] => user [PID] => 12345 [%CPU] => 0.0 [%MEM] => 0.0 [VSZ] => 1720 [RSS] => 8 [TT] => ?? [STAT] => Is [STARTED] => 6:00PM [TIME] => 0:00.01 [COMMAND] => php someproces.php > logfile ) */ ////////////////////////////////////////////// function getpidinfo($pid, $ps_opt="aux"){ $ps=shell_exec("ps ".$ps_opt."p ".$pid); $ps=explode("\n", $ps); if(count($ps)<2){ trigger_error("PID ".$pid." doesn't exists", E_USER_WARNING); return false; } foreach($ps as $key=>$val){ $ps[$key]=explode(" ", ereg_replace(" +", " ", trim($ps[$key]))); } foreach($ps[0] as $key=>$val){ $pidinfo[$val] = $ps[1][$key]; unset($ps[1][$key]); } if(is_array($ps[1])){ $pidinfo[$val].=" ".implode(" ", $ps[1]); } return $pidinfo; } ?> --was-- <? /* mixed getpidinfo(mixed pid [, string system_ps_command_options]) this function gets PID-info from system ps command and return it in useful assoc-array, or return false and trigger warning if PID doesn't exists $pidifo=getpidinfo(12345); print_r($pidifo); Array ( [USER] => user [PID] => 12345 [%CPU] => 0.0 [%MEM] => 0.0 [VSZ] => 1720 [RSS] => 8 [TT] => ?? [STAT] => Is [STARTED] => 6:00PM [TIME] => 0:00.01 [COMMAND] => php someproces.php > logfile ) */ ////////////////////////////////////////////// function getpidinfo($pid, $ps_opt="aux"){ $ps=shell_exec("ps ".$ps_opt."p ".$pid); $ps=explode("\n", $ps); if(count($ps)<2){ trigger_error("PID ".$pid." doesn't exists", E_USER_WARNING); return false; } foreach($ps as $key=>$val){ $ps[$key]=explode(" ", ereg_replace(" +", " ", trim($ps[$key]))); } foreach($ps[0] as $key=>$val){ $pidinfo[$val] = $ps[1][$key]; unset($ps[1][$key]); } if(is_array($ps[1])){ $pidinfo[$val].=" ".implode(" ", $ps[1]); } return $pidinfo; } ?> http://php.net/manual/en/function.getmypid.php

« previous php.notes (#141842) next »