日後應該會用的到
PHP
<?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;
}
?>
在其他程式執行下列函數即可得到你要的數值啦!
Examples:
<?php
echo "CPU use of Program: ".GetProgCpuUsage($randomprogram)."%";
echo "Memuse of Program: ".GetProgMemUsage($randomprogram)."%";
?>
沒有留言:
張貼留言