我有以下來源,希望有SCHED_RR優先90:sched_setscheduler適用於所有線程或主線程?
int main(int argc, char** argv)
{
const char *sched_policy[] = {
"SCHED_OTHER",
"SCHED_FIFO",
"SCHED_RR",
"SCHED_BATCH"
};
struct sched_param sp = {
.sched_priority = 90
};
pid_t pid = getpid();
printf("pid=(%d)\n",pid);
sched_setscheduler(pid, SCHED_RR, &sp);
printf("Scheduler Policy is %s.\n", sched_policy[sched_getscheduler(pid)]);
pthread_t tid ;
pthread_create(&tid , NULL, Thread1 , (void*)(long)3);
pthread_create(&tid , NULL, Thread2 , (void*)(long)3);
pthread_create(&tid , NULL, Thread3 , (void*)(long)3);
while(1)
sleep(100);
}
而殼「頂」,我可以看到進程有PR與-91,看起來像它的工作原理, 據我所知,在Linux中,線程1和線程和thread3是從主線程不同的任務 ,他們只是共享相同的虛擬內存,我想知道 在這個測試中,我需要添加
pthread_setschedparam(pthread_self(), SCHED_RR, &sp);
所有線程1,線程2和thread3,這樣所有這3個可以被調度帶着SCHED_RR帶領 ?!或者我不需要這樣做?!我怎麼能觀察 thread1,thread2和thread3線程是SCHED_RR還是SCHED_OTHER?!
編輯:
sudo chrt -v -r 90 ./xxx.exe
將看到:
pid 7187's new scheduling policy: SCHED_RR
pid 7187's new scheduling priority: 90
我怎麼能肯定這只是針對主線程?!或者pid 7187 中的所有線程都是SCHED_RR策略?!並再次,如何觀察它?!