How to run a program with SCHED_RR policy from command line?
Use the chrt
command with chrt --rr <priority between 1-99> <command>
Example:
chrt --rr 99 ls
Note that setting SCHED_RR
require root permissions, so you either have to be root or run it with sudo.
You can also use chrt
to give a running process realtime priority:
chrt -p --rr <priority between 1-99> <pid>
The same commands applies for other scheduling classes as well, albeit with a different parameter instead of -rr:
Scheduling policies:
-b | --batch set policy to SCHED_BATCH
-f | --fifo set policy to SCHED_FIFO
-i | --idle set policy to SCHED_IDLE
-o | --other set policy to SCHED_OTHER
-r | --rr set policy to SCHED_RR (default)
Edit:
In the Firefox case, it must be spesific to Firefox. In a multithreaded application I wrote myself, all the threads keep the RR class. As seen in your output, two threads have class RR, so it's not only the parent thread either.
Edit 2:
Try starting the process with chrt
instead of rescheduling an existing pid. It appears that if you reschedule, only the first thread gets RR class. However, if you start it with chrt
, every thread gets it.
Just add this code inside the thread code:
pthread_t this_thread = pthread_self ();
struct sched_param params;
params.sched_priority = sched_get_priority_max (SCHED_RR);
pthread_setschedparam (this_thread, SCHED_RR, ¶ms);
This will give each thread maximum RR priority.