I have created two threads . By default they have a priority of 0 which i can see using
pthread_getschedparam and then i try to increase their priority to say 2 and 3 respectively . But Whn i try do do so i get an error
error setting priority for T1: (1), Operation not permitted
error setting priority for T2: (1), Operation not permitted
I have used the scheduling policy of SCHED_RR for them
int sched = SCHED_RR;
and then performed this :-
if (pthread_setschedparam(t1, sched, &t1_param) != 0)
{
std::cout << "error setting priority for T1: (" << errno << "), " <<
strerror(errno) << std::endl;
}
What is the reason why I am not able to modify my threads priority because priority is within limit of 1 to 99 for SCHED_RR.
DISCLAIMER: I’m not an expert at Linux security, and the following advice might compromise or damage your computer.
In recent versions of Linux, there is a resource limit,
RLIMIT_RTPRIO, which specifies the maximum real-time priority you can use. You can check this from the shell:On my version of Ubuntu (and probably yours too) there’s also a hard limit of zero, so you can’t simply use
ulimitorsetrlimitto raise this. One way to raise the hard limit is to add a line to/etc/security/limits.conflike this (replacing<username>with your username):Then you should be able to use
ulimit(from the shell) orsetrlimit(from your program) to set the soft limit to the priority you need; alternatively, you could set that automatically by adding a second line tolimits.conf, replacinghardwithsoft.Do be careful running programs with real-time priority; it can kill the system if it starts misbehaving.