System Q&A

Q: 如何设置线程优先级为RR99?

设置参考code如下:

struct sched\_param sched3;  
sched3.sched\_priority = 99;
pthread\_create(&t3, NULL, (consumer), (void \*)6);  
pthread\_setname\_np(t3,"TESTThread");
rc = pthread\_setschedparam(t3, SCHED\_RR, \&sched3);

设置完可以通过cat /proc/pid/stat查看:

需要注意的是,pid是对应线程的pid而不是主线程的,可以通过运行htop,然后输入t查看线程pid:

...