Parse linux "top" in PHP? -


i'm working on monitoring tool in php. should display % cpu usage of single process pid . keep in mind can't use ps because takes total usage , divides time process has been running. that's average usage. need usage in moment php file ran.

here's i'm trying, seems close need in terminal php won't print anything.

$cmd = "top -n 1 -p 30100"; echo exec($cmd); 

is there maybe better way of doing this? can install utilities if provide functionality need.

tl;dr need %cpu of process pid, simple possible avoid parsing

top -n1 -p 30100 |grep -e 30100 | awk '{print $10}'  

Popular posts from this blog