title: Cannot set thread priority to real time despite using cap_sys_nice
body: <p>I have an application that checks on POSIX environment whether thread priorities can be set to real time by calling</p>
  <pre><code>struct sched_param param;
  param.sched_priority = 1;
  int canSetRealTimeThreadPriority = (pthread_setschedparam(pthread_self(), SCHED_FIFO, &amp;param) == 0);
  </code></pre>
  <p>On one system <code>system A</code> this works, but on another <code>system B</code> the check fails and I would like to find out why.</p>
  <p>On both systems:</p>
  <ul>
  <li><p>the application is started as a <code>systemd</code> service via a service startup script.</p>
  </li>
  <li><p>calling <code>getcap</code> on the binary returns among others <code>cap_sys_nice+eip</code>.</p>
  </li>
  <li><p>the service script defines that the application is run by a non root user via <code>User=[non root user]</code></p>
  </li>
  <li><p>the service scripts sets <code>LimitRTPRIO=20</code></p>
  </li>
  <li><p>calling <code>sysctl -n kernel.sched_rt_runtime_us</code> returns <code>950000</code>, which should be the default</p>
  </li>
  <li><p>calling <code>sysctl -n kernel.sched_rt_period_us</code>returns <code>1000000</code>, which should be the default</p>
  </li>
  <li><p><code>systemctl show [serviceName]</code> returns among others <code>LimitRTPRIO=20</code></p>
  </li>
  <li><p>calling the limits on the running process of the application (<code>prlimit --pid [application_pid]</code>) will show among others:</p>
  </li>
  </ul>
  <pre><code>RESOURCE   DESCRIPTION                             SOFT      HARD UNITS
  NICE       max nice prio allowed to raise             0         0
  RTPRIO     max real-time priority                    20        20
  RTTIME     timeout for real-time tasks        unlimited unlimited microsecs
  </code></pre>
  <p>On <code>system B</code> where it doesn't allow real time thread priorities:</p>
  <ul>
  <li><code>etc/security/limits.conf</code> contains line</li>
  </ul>
  <pre><code>[non root user]    -    rtprio    20
  </code></pre>
  <ul>
  <li>kernel version is <code>3.10.0-862.el7.x86_64</code> and OS version <code>Red Hat Enterprise Linux Server release 7.4 (Maipo)</code></li>
  </ul>
  <p>On <code>system A</code> where realtime thread priorities can be set:</p>
  <ul>
  <li>kernel version is <code>3.10.0-957.56.1.el7.x86_64</code> and OS version <code>Red Hat Enterprise Linux Server release 7.6 (Maipo)</code></li>
  </ul>
  <p>When I test on <code>system A</code> and remove <code>cap_sys_nice+eip</code> from the binary via <code>setcap '' [binary]</code> I also cannot set real time thread priorities. I assume some setting on <code>system B</code> overrides the <code>cap_sys_nice</code> setting because it has a higher priority, so I wonder what that can be.</p>