如何获得对pthread_setschedparam的许可 [英] How to get permission for pthread_setschedparam

查看:412
本文介绍了如何获得对pthread_setschedparam的许可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在具有Angstrom Linux版本3.2.18的BeagleBone上实时运行C ++程序.该程序调用pthread_setschedparam尝试提高其优先级.以root用户身份登录时,出现不允许操作"错误.但是,如果我首先在shell提示符下提升为超级用户"su",则对pthread_setschedparam的调用会成功.

I need to run a C++ program at real-time priority on a BeagleBone with Angstrom Linux version 3.2.18. The program calls pthread_setschedparam to attempt to elevate its priority. When logged in as root, I get an "Operation not permitted" error. However, if I first elevate to superuser "su" at the shell prompt, the call to pthread_setschedparam is successful.

如何在不先运行"su"的情况下获得相同的结果?我需要将此程序作为在启动时自动启动的服务来运行.

How can I achieve the same result without running "su" first? I need to run this program as a service that starts automatically at boot time.

推荐答案

In the manpage for pthread_setschedparam (I assume that's what you meant), it states under Notes:

有关更改线程的调度策略和优先级所需的权限以及其效果的描述,以及每种调度策略中优先级的允许范围的详细信息,请参阅sched_setscheduler(2).

For a description of the permissions required to, and the effect of, changing a thread's scheduling policy and priority, and details of the permitted ranges for priorities in each scheduling policy, see sched_setscheduler(2).

该手册页中,它在特权和资源限制下详细说明:

In that manpage, it's detailed under Privileges and resource limits:

在2.6.12之前的Linux内核中,只有特权(CAP_SYS_NICE)进程可以设置非零静态优先级(即,设置实时调度策略).非特权进程可以进行的唯一更改是设置SCHED_OTHER策略,并且只有在sched_setscheduler()的调用者的有效用户ID与目标进程(即该进程)的实际或有效用户ID匹配时,才能进行此操作.由pid指定),其策略正在更改.

In Linux kernels before 2.6.12, only privileged (CAP_SYS_NICE) processes can set a nonzero static priority (i.e., set a real-time scheduling policy). The only change that an unprivileged process can make is to set the SCHED_OTHER policy, and this can only be done if the effective user ID of the caller of sched_setscheduler() matches the real or effective user ID of the target process (i.e., the process specified by pid) whose policy is being changed.

从Linux 2.6.12开始,RLIMIT_RTPRIO资源限制为SCHED_RR和SCHED_FIFO策略的非特权进程的静态优先级定义了上限.更改调度策略和优先级的规则如下:

Since Linux 2.6.12, the RLIMIT_RTPRIO resource limit defines a ceiling on an unprivileged process's static priority for the SCHED_RR and SCHED_FIFO policies. The rules for changing scheduling policy and priority are as follows:

  • 如果未特权进程的RLIMIT_RTPRIO软限制为非零,则它可以更改其调度策略和优先级,但前提是不能将优先级设置为高于其当前优先级及其最大值的最大值.RLIMIT_RTPRIO软限制.

  • If an unprivileged process has a nonzero RLIMIT_RTPRIO soft limit, then it can change its scheduling policy and priority, subject to the restriction that the priority cannot be set to a value higher than the maximum of its current priority and its RLIMIT_RTPRIO soft limit.

如果RLIMIT_RTPRIO软限制为0,则唯一允许的更改是降低优先级或切换到非实时策略.

If the RLIMIT_RTPRIO soft limit is 0, then the only permitted changes are to lower the priority, or to switch to a non-real-time policy.

遵循相同的规则,只要进行更改的流程的有效用户ID与目标流程的实际或有效用户ID相匹配,另一个不受特权的流程也可以进行这些更改.

Subject to the same rules, another unprivileged process can also make these changes, as long as the effective user ID of the process making the change matches the real or effective user ID of the target process.

特殊规则适用于SCHED_IDLE:在此策略下运行的非特权进程无法更改其策略,无论其RLIMIT_RTPRIO资源限制的值如何.

Special rules apply for the SCHED_IDLE: an unprivileged process operating under this policy cannot change its policy, regardless of the value of its RLIMIT_RTPRIO resource limit.

特权(CAP_SYS_NICE)进程忽略RLIMIT_RTPRIO限制;与较早的内核一样,它们可以对调度策略和优先级进行任意更改.有关RLIMIT_RTPRIO的更多信息,请参见getrlimit(2).

Privileged (CAP_SYS_NICE) processes ignore the RLIMIT_RTPRIO limit; as with older kernels, they can make arbitrary changes to scheduling policy and priority. See getrlimit(2) for further information on RLIMIT_RTPRIO.

这篇关于如何获得对pthread_setschedparam的许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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