我有以下来源,喜欢将 SCHED_RR 优先级设置为 90 :
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);
}
当 shell "top" 时,我可以看到该进程的 PR 为 -91 ,看起来它可以工作,
据我所知,在Linux中,thread1和thread2和thread3是不同的任务
从主线程来看,它们只是共享相同的虚拟内存,我想知道
在这个测试中,我是否需要添加
pthread_setschedparam(pthread_self(), SCHED_RR, &sp);
对于所有线程1、线程2和线程3,以便可以调度所有这3个线程
与 SCHED_RR ?!或者我不需要这样做?我怎样才能观察到
thread1、thread2 和 thread3 线程是 SCHED_RR 或 SCHED_OTHER ?!
Edit :
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 政策吗?!再说了,如何观察呢?!