user1534664
user1534664

Reputation: 3418

Inside the Linux kernel, does the `nice` priority level of a task get modified anywhere else beside these cases?

From within the Linux kernel, I want to overwrite the nice priority (with a hardcoded value) of all regular processes (e.g. of the scheduling class SCHED_NORMAL) that have an uneven process ID.

I discovered that the default settings of a process are initiated in /source/init/init_task.c, including the priority value which is set to default value MAX_PRIO - 20 (i.e., 120), as can be seen in the definition of the struct definition of init_task.

My reasoning is that if I were to modify these default settings in init_task.c, it should cover all cases with exception to any users calling the system call sys_setpriority (by using the nice command for example). Is this correct, or are there any other cases where the task's prio may be modified?

Upvotes: 0

Views: 335

Answers (1)

Marco Bonelli
Marco Bonelli

Reputation: 69326

I discovered that the default settings of a process are initiated in /source/init/init_task.c

No. That's the definition of the init task itself, it's not used to init[ialize] new tasks. The init task is the first userspace task that is ran by the kernel upon startup, and its task_struct is hardcoded for performance and ease of use. Any other task is created through fork(2)/clone(2).

My reasoning is that if I were to modify these default settings in init_task.c, it should cover all cases

It doesn't cover anything really, just the initial priority of init, which can very well overwrite it itself since it runs as root.


The priority of a task can be changed in different ways, but the kernel should not "automatically" change priority of tasks, at least to my knowledge.

Therefore, if you want to "control" the priority in such a way, your best bet would be to change the code of fork (specifically clone_process()), since forking is the only way to create new processes in Linux.

Other than that, there are other syscalls that can end up modifying the priority of a process. Taking a quick glance at the kernel code, at least sched_setscheduler (source), sched_setparam (source), and setpriority (source).

Upvotes: 1

Related Questions