soyuka / pidusage

Cross-platform process cpu % and memory usage of a PID
MIT License
512 stars 55 forks source link

why don't use 'top' in darwin os #34

Closed ysstech closed 7 years ago

ysstech commented 7 years ago

darwin os use command "ps -o pcup,rss -p [pid]" result is different from use command "top -pid [pid]"

ps: CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to. CPU usage is unlikely to add up to exactly 100%.

top: The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' interactive command.

so why don't use 'top'?

soyuka commented 7 years ago

Because ps -o pcpu,rss -p works on darwin, sunos and freebsd.

Anyway I don't see why we could not implement top. Do you have any idea on how I may launch top without it being interactive?

Still, the best would be to use sysctl directly.

soyuka commented 7 years ago

Closing because no answer.