Operation not allowed when setting new priority for stream

I created two threads. By default, they have priority 0, which I can see using pthread_getschedpaparam, and then I try to increase their priority to say 2and 3accordingly. But, if I try to do this, I get an error

     error setting priority for T1: (1), Operation not permitted
     error setting priority for T2: (1), Operation not permitted 

I used a schedule policy SCHED_RRfor them

       int sched = SCHED_RR;

and then did the following: -

   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 cannot change the priority of my threads, since the priority is in the range from 1to 99for SCHED_RR.

+3
source share
4 answers

: Linux, .

Linux RLIMIT_RTPRIO, , . :

> ulimit -r
0

Ubuntu (, , ) , ulimit setrlimit, . /etc/security/limits.conf, ( <username> ):

<username> hard rtprio 99

ulimit ( ) setrlimit ( ), ; , , limits.conf, hard soft.

> ulimit -Hr # show hard limit
99
> ulimit -r
0
> ulimit -Sr 1 # set soft limit
> ulimit -r
1

; , .

+5

. .

Linux SCHED_OTHER. (.. SCHED_RR , ), root. root, .

( , - Linux 2.2. , , , )

+1

can you try with SCHED_BATCH?

Above may not require root privileges

0
source

Another reason this call fails if you are a root user and work in rlimits is cgroups, see https://unix.stackexchange.com/a/511261/232485.

0
source

All Articles