问题
I found some function 'renice' that changes the nice value of process.
But I want to know how to change priority in kernel code.
Is it okay that just changing the priority value in sched_entity of process?
回答1:
If you want to change the niceness of the process programmatically, I would advise against setting these values in the kernel struct directly. Instead, you can utilize several POSIX functions such as setpriority
or pthread_setschedparam
.
The default scheduler policy on Linux is SCHED_OTHER
, so you're, by default, achieving the same thing using these two functions, as SCHED_OTHER
just uses niceness level to schedule.
If you have access to the task_struct
, in order to achieve this directly, you just need to set static_prio
in task_struct
.
来源:https://stackoverflow.com/questions/32709518/how-to-change-linux-kernel-process-priority-in-programmatic-way