Use cpu in script in osx

In linux, I can get the current CPU usage from /proc/stat ; is there an OSX equivalent? Or some kind of utility that returns easily parsed and consistent output? I need this in a Ruby program.

+4
source share
2 answers

sysctl easy to parse; you can get the average load value by checking the vm.loadavg value.

 $ sysctl vm.loadavg vm.loadavg: { 0.57 0.80 0.85 } 
+1
source

There are several ways, all I know rely on command line tools:

If you want parsing efforts to be low, try reducing the result by applying useful options to the tools.

+1
source

All Articles