Search code examples
macosterminalprocesscpu-usageuptime

OSX Activity Monitor vs Avg Load


I know that Avg Load (obtained using "uptime" command on terminal) gives the average of amount of process that are in waiting or ready state. I can see that avg load of my mac is around 2-3. But, when I open activity monitor at the same time, it shows there are hundreds of processes running. I want to know why there is such huge difference.


Solution

  • On Mac, the name of the state that uptime is checking is "runnable" which includes processes currently running on a CPU and processes that would be running on a CPU if there were a core available for them. So a load average less than the number of system cores indicates that there's little or no contention for cores. Every process that would like a core, has one. A load average larger than the number of cores indicates that sometimes runnable processes are having to wait to be scheduled.

    Most processes spend the vast majority of their time in some state other than runnable. The most common state on Mac is called "sleeping," which means the process is waiting for something from the kernel. A very common thing to wait for is user input. It might also be waiting for disk or network traffic or a timer. But in any case, the process is blocked, waiting for something from the kernel, and even if there were a core available, it wouldn't be scheduled because it wouldn't have anything to do.

    That's why hundreds of processes can be alive, but have no impact on the CPU...sort of. Processes are not "charged" for the time the kernel spends working on their behalf. So you'll see a fake process called kernel_task that can be a substantial proportion of the total. This is stuff the kernel is doing, sometimes in response to things requested by a user process (such as disk I/O or sending network packets). On the other, hand kernel_task also represents time that the kernel "steals" from the system to manage the CPU temperature. So, it can sometimes be difficult to really work out what kernel_task usage means.