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.

asked Jan 12, 2017 by harryxiyou (5,830 points)

1 Answer

Best answer

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


answered Jan 12, 2017 by harryxiyou (5,830 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost