Why does pthread_setschedparam() produce EPERM on

2019-09-04 04:27发布

I am writing an application with c++ and NetBeans on opensuse 11.4 with kernel 2.6.37.1-1.2 (logged in as root). This application creates a thread and when run gives this result:

    sched_param param;
    param.__sched_priority = -1;
    policy = SCHED_FIFO;
    param.__sched_priority = 50;
    result = pthread_setschedparam(m_thread,policy,&param);

result = 1(EPERM (not permitted))

Why?

1条回答
再贱就再见
2楼-- · 2019-09-04 05:07

erm... because it is not permitted? Check the following settings:

A non-privileged process cannot set the real-time priority higher than its RLIMIT_RTPRIO setting. You can change this with an "rtprio" entry in /etc/security/limits.conf (settings are applied on login, so changes won't affect existing login sessions).

Privilege is determined by the CAP_SYS_NICE capability.

Something like this should go in the config file:

domain       type    item     value
@group       soft    rtprio   100

The given group will have a soft rtprio limit to 100. This will work, assuming your PAM configuration uses pam_limits.

You may have to make sure of the hard limit too:

@group       hard    rtprio   100
查看更多
登录 后发表回答