7

I know you can change a process niceness with setpriority or nice or renice.

However, does Linux automatically adjust/change a process niceness without user input?

I have a process for which I use setpriority in C, like so:

setpriority(PRIO_PROCESS, 0, -1)

When the process is running, I can see its niceness value is now -1 by running htop.

While investigating a crash on a remote machine, the output of htop was provided to me. I noticed that the niceness value for this process had changed on one instance to 0 and on another instance to 6. I'd like to know if this was changed by the kernel or if the only way to change this value is by having a user or script deliberately make the change.

  • 1
    I don't think the kernel does it, but the CPU scheduler does choose what to prioritize. There are many available CPU schedulers. A tool that automatically adjusted niceness would be interesting. – Alexander Jan 12 '17 at 15:00
  • 1
    As you, I suspect the kernel does not change it on its own. I understand the scheduler has its own algorithm to prioritize processes. I'm asking because I'm looking at some logs that clearly show the niceness of a particular process changed. I wanted to rule out someone manually changing it using something as renice. – Luis Jan 12 '17 at 15:09
  • 1
    @Leco Add this info to the question and also provide a small sample from your logs showing that the niceness value changed. – Kusalananda Jan 12 '17 at 15:30
  • @roaima The process priority is set in C code with setpriority. The process niceness is observed with htop. – Luis Jan 12 '17 at 17:14
4
+50

To my knowledge, the Linux kernel does not change the niceness of a process, and I fail to see why it would since it doesn't have to to lower the priority of a process. The niceness is an information given to the kernel, telling it how nice that process is willing to be. The kernel scheduler is free to take this information into account the way it wants in order to change the priority of a process, it doesn't need to change its value.

On the other hand, in user land, there are daemons like AND whose task is to renice processes according to rules set up by the admin. Do you have such a daemon installed on your server?

However, the AND daemon does not renice processes owned by root, and since you set a priority of -1 with setpriority(), I assume this is the case here. Therefore, the only reason I see for that change in niceness is user interaction.

That said, since you are using htop, it is possible that the process has been reniced inadvertently by pressing the ] key or the F8 key.

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.