How to set process with lowest priority?

In system, sometimes, we need backstage threads with very very low priority since it cannot preempt any normal process asks for CPU.

SCHED_IDLE class satisfies this requirement which has the priority lower than “nice=19” of CFS. Following code does this.

 241 void set_idle_priority(void) {                                                                             
 242     struct sched_param param;                                                                              
 243     param.sched_priority = 0;                                                                              
 244     int s = pthread_setschedparam(pthread_self(), SCHED_IDLE, ¶m);                                     
 245     if (s != 0) handle_error("Pthread_setschedparam error!n");                                                 
 246 }  

Check the scheduler class after you set the process.

$ chrt -p 2370
pid 2370's current scheduling policy: SCHED_IDLE
pid 2370's current scheduling priority: 0


Leave a Reply

Your email address will not be published. Required fields are marked *