Fun with realtime scheduler (3)

Well we figured out how to give our process SCHED_FIFO priority last time (see here) right? But then I started wondering about multithreaded apps and if the call to sched_setscheduler() works for the complete process or only for the current thread.

So I created a small test program with a main loop and a small thread that raises its prio to SCHED_FIFO. The main thread runs at unmodified prio. The results?

benjamin@benjamin-laptop:~$ ps -eLO pid,tid,lwp
24071 24071 24071 24071 S pts/9    00:00:00 ./a.out
24071 24071 24072 24072 S pts/9    00:00:00 ./a.out

So we have two thread ID’s: 24071 and 24072. Here’s the result from chrt:

benjamin@benjamin-laptop:~$ chrt -p 24071
pid 24071's current scheduling policy: SCHED_OTHER
pid 24071's current scheduling priority: 0
benjamin@benjamin-laptop:~$ chrt -p 24072
pid 24072's current scheduling policy: SCHED_FIFO
pid 24072's current scheduling priority: 99

So there we have our answer, the sched_setscheduler() call only works for the current TID, not for all threads…