Click to See Complete Forum and Search --> : Getting Process Data CPU usage


Lexx
02-25-2003, 12:41 PM
Hello,

I was wondering if there was a system call or whatnot with which I could retrieve 'top' data and prevent let's say httpd from hitting 99% by rebooting.

Looking forward to your replies.
Alex

chrism01
02-26-2003, 01:54 PM
top -n1
gives you a one shot list of what's running.
The -p option allows you to specify process id to check. You can get this from ps -ef|grep <name of process eg httpd>
Luckily you can specify up to 20 proc ids as httpd usually has several procs running.

Lexx
02-28-2003, 06:43 PM
Thanks Chris.

Top seems to have different behavior tho,

this:

$cmd2 = 'top -n1|grep httpd';
$fp = popen( $cmd2, 'r' );

while ( !feof( $fp ) ) {
$buffer = fgets( $fp, 4096 );
echo $buffer.'<br>';
}

pclose( $fp );


Doesn't seem to print top data as it otherwise would. Any ideas?

chrism01
02-28-2003, 08:31 PM
PHP is not 1 one of my skills, but i would point out that if it was in shell, you'd use backquotes (`) around the cmd, otherwise you've just got a string, not a cmd.
Does PHP have a similar distinction; ie how does it tell you want it to run a cmd ,not treat as a string ??