I am trying to test out the renice command on my Mac, it seems to be having no effect. This is how I'm testing it:

I have a dual core CPU with hyper threading, so I run 6 instances of node -e 'while(1){}' which, combined, max out my CPU. (Alternatively, run while true; do echo running > /dev/null ; done if you don't have node.)

I then get a PID of one of the node processes, either by the activity monitor application or pgrep, and then run sudo renice -n 19 -p $PID.

By looking at the activity monitor application or htop, the CPU usage of all of the node processes are still equivalent:

enter image description here

My understanding was that the process that I reniced would have a low priority, and so would not use a significant amount of CPU time when there are other processes using it.

Am I misunderstanding something about renice? Or is this a bug in macOS?

  • 3
    You have four cores, and you have four running processes. Why would each not get their own core? – Ignacio Vazquez-Abrams May 8 '18 at 5:58
  • 3
    A nice process would still get 100% of a CPU if it was available to it. – Kusalananda May 8 '18 at 6:10
  • @IgnacioVazquez-Abrams No, I have 2 cores, with hyperthreading. Hyperthreading gives, on average is about 30% of a core's worth of performance. Therefore 4 threads may not (on avg) be able to run in parallel. – Dylanthepiguy May 8 '18 at 7:52
  • @IgnacioVazquez-Abrams , @Kusalananda , I can add more node processes, e.g. 6, and the same effect is produced - same cpu usage. I have edited my question to show this – Dylanthepiguy May 8 '18 at 7:53
  • 1
    Running some rudimentary tests I’m seeing this too on 10.13.4. The curious thing is that on my FreeBSD system the Priority of a process shifts with the niceness. On macOS the Priority remains the same, so I wonder if it is a bug. Might be worth flagging to Apple if anyone has an appropriate account. – forquare May 18 '18 at 8:26

Running some rudimentary tests I’m seeing this too on 10.13.4.

I wrote a small C program called looper which did some basic maths in an infinite loop:

#include <stdio.h>

int main(){
    unsigned long long prev = 0;
    unsigned long long current = 1;
    unsigned long long total = 0;

        total = current + prev;
        prev = current;
        current = total;
        printf("%llu\n", total);

I ran multiple copies of this on my FreeBSD box and examined them using htop(1). Using renice(8) I could see the Nice value being incremented, the Priority value being incremented, and the CPU percentage decreasing - expected behavior.

I ran the same program on macOS 10.13.4 and repeated the process. While I could see the Nice value incrementing, the Priority value and CPU percentage remained consistent.

I wonder if it is a bug, I've not had cause to look this closely at Nice values in macOS before - the behavior has been close enough to what I expected that I've not been inclined to investigate.

If you have a developer account it would be worth reporting this to Apple.

  • 2
    Thanks! I have been able to replicate that the priority has not been increased using ps -o pid,comm,pri,nice -p $(pgrep node). I've reported this to apple again on their developer bug reporter. Hopefully we get a response in any reasonable amount of time! – Dylanthepiguy May 18 '18 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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