I have a program that generates a stream in real time with code as follows:
schparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
getrlimit(RLIMIT_RTPRIO , &rlim);
rlim.rlim_cur = schparam.sched_priority;
setrlimit(RLIMIT_RTPRIO , &rlim);
result = pthread_setschedparam(pthread_self(),SCHED_FIFO, &schparam);
if(result != 0 )
printf("failed to set priority\n");
My system limit by default does not allow scheduled RT threads, so I need to call setrlimit to raise this value. The above code works as needed when I enter the root shell and run the program manually.
However, when I start the program automatically using systemd at startup, the schedule is not set with a permission error. The setrlimit call seems to work, judging by the return value and subsequent getrlimit calls inside the process. But the call to pthread_setschedparam does not seem to understand that the limit has been increased.
Again, all this works great when I run the program manually. What am I missing here?
source
share