如何以编程方式更改linux内核进程优先级? [英] How to change linux kernel process priority in programmatic way?
问题描述
我发现了一些函数"renice",该函数改变了进程的美观值.
I found some function 'renice' that changes the nice value of process.
但是我想知道如何更改内核代码的优先级.
But I want to know how to change priority in kernel code.
可以只更改进程的sched_entity中的优先级值吗?
Is it okay that just changing the priority value in sched_entity of process?
推荐答案
如果要以编程方式更改进程的美观程度,建议不要在内核结构中直接设置这些值.而是可以使用几个POSIX函数,例如setpriority
或pthread_setschedparam
.
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
.
Linux上的默认调度程序策略是SCHED_OTHER
,因此默认情况下,您会使用这两个功能来实现相同的目的,因为SCHED_OTHER
只是使用尼斯级别进行调度.
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.
如果可以访问task_struct
,则要直接实现此目的,只需在task_struct
中设置static_prio
.
If you have access to the task_struct
, in order to achieve this directly, you just need to set static_prio
in task_struct
.
这篇关于如何以编程方式更改linux内核进程优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!