How to change linux kernel process priority in programmatic way?

我与影子孤独终老i 提交于 2021-01-29 07:38:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!