I want to find a way that I can call a command or method, and get an int with the cpu usage the moment I called it. Not like top, where it keeps refreshing.
I am writing an app in MacRuby, so I can either use a cl command, or some ruby api.
any thoughts?
thanks
edit: can I somehow call top and get one frame o开发者_C百科f it in ruby? and from there I can get the percentage I need. Although I guess this way is not ideal..
kinda SOLVED: top -l 1
on mac, top -n 1
on linux. It runs top for just one frame.
The w
command gives a output which contains load average in the first line.
So try w | head -1
It's not an int, and not strictly "CPU usage", but it might be a start.
Have you checked whether there's a command-line option for top
to just give an instantaneous once-only output, and have you looked at ps
?
精彩评论