如何以编程方式更改linux内核进程优先级? [英] How to change linux kernel process priority in programmatic way?

查看:82
本文介绍了如何以编程方式更改linux内核进程优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些函数"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函数,例如setprioritypthread_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆