Linux – Does Linux Change a Process Niceness Automatically

linuxnicepriorityprocess

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.

Best Answer

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.

Related Question