note 83170 added to function.exec

From: Date: Tue, 13 May 2008 20:29:06 +0000
Subject: note 83170 added to function.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-139359@lists.php.net to get a copy of this message
I was thinking on how to make a wee command that can be used for getting the Memory AND CPU usage of a program. <?php function GetProgCpuUsage($program) { if(!$program) return -1; $c_pid = exec("ps aux | grep ".$program." | grep -v grep | grep -v su | awk {'print $3'}"); return $c_pid; } function GetProgMemUsage($program) { if(!$program) return -1; $c_pid = exec("ps aux | grep ".$program." | grep -v grep | grep -v su | awk {'print $4'}"); return $c_pid; } ?> What this does is get the program's information, and splits it into either the CPU or MEM usage. Examples: <?php echo "CPU use of Program: ".GetProgCpuUsage($randomprogram)."%"; echo "Memuse of Program: ".GetProgMemUsage($randomprogram)."%"; ?> Nice and simple. :) ---- Server IP: 87.124.64.96 Probable Submitter: 79.65.89.30 ---- Manual Page -- http://www.php.net/manual/en/function.exec.php Edit -- https://master.php.net/note/edit/83170 Del: integrated -- https://master.php.net/note/delete/83170/integrated Del: useless -- https://master.php.net/note/delete/83170/useless Del: bad code -- https://master.php.net/note/delete/83170/bad+code Del: spam -- https://master.php.net/note/delete/83170/spam Del: non-english -- https://master.php.net/note/delete/83170/non-english Del: in docs -- https://master.php.net/note/delete/83170/in+docs Del: other reasons-- https://master.php.net/note/delete/83170 Reject -- https://master.php.net/note/reject/83170 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139359) next »