Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to return the load averages, excluding any load caused by nice'd processes?

We have a load balancing mechanism in place that checks the load of multiple Linux servers, and submits a job to the server having the lowest load. We had a scenario where all servers had too high a load and so no server could be selected in the load balancing. However, I noticed that the servers were handling a bunch of nice'd processes, so although the load averages were high, it was still "safe" to submit another job.

Let me know if clarification is needed. Thanks.

share|improve this question
up vote 5 down vote accepted

You can write up your own script that uses ps to list all processes in the run/runnable state without a nice value greater than 0. The specific syntax you need to use will differ based on your version of ps. Something like this may work:

ps -eo state,nice | awk 'BEGIN {c=0} $2<=0 && $1 ~ /R/ { c++ } END {print c-2}'

It runs ps collecting the state and nice level of all processes and pipes the output to awk which sets a count variable c and increments it whenever the second column (nice) is less than or equal to 0 and the first column includes R (for runnable). Once it's done it prints out the value of c after subtracting 2. I subtract 2 because the ps and the awk commands will almost always be considered runnable for the duration of the command's execution. The end result will be a single number which represents the number of processes that were runnable at the time that the script executed excluding itself and processes run nicely, which is essentially the instantaneous load on the machine. You'd need to run this periodically and average it over 1, 5, and 15 minutes to determine the typical load averages of the machine.

share|improve this answer
Thanks for this answer. I haven't had a chance to test it yet, but I plan to and will get back to you. – Banjer Sep 27 '11 at 17:58

I just needed something similar. The answer from mkomitee helped me.

But the command ps -e lists only processes. The load should take into account that a process may have many threads running in parallel. I suggest to add the option -L to the call of ps to list all threads:

ps -eLo state,nice | awk 'BEGIN {c=0} $2<=0 && $1 ~ /R/ { c++ } END {print c-2}'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.