gpt4 book ai didi

linux - 如何获得 pthread_setschedparam 的权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:39:53 24 4
gpt4 key购买 nike

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

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

最佳答案

manpage对于 pthread_setschedparam(我想这就是你的意思),它在注释下说明:

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).

that manpage ,在权限和资源限制下有详细说明:

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.

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:

  • 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.

  • 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.

  • 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.

  • 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.

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.

关于linux - 如何获得 pthread_setschedparam 的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14971910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com