note 83170 deleted from function.exec by cmb
| From: | cmb@php.net | Date: | Sun, 24 Nov 2019 08:56:39 +0000 |
| Subject: | note 83170 deleted from function.exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213222@lists.php.net to get a copy of this message | ||
Note Submitter: dweston at hotmail dot co dot uk
----
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. :)