我有以下代码,它改变了当前线程的优先级 . 我作为参数传递了90,但看起来线程以优先级19运行 . 我有:
-
检查ulimit -r设置为99
-
进程以root身份运行
我如何知道该进程以优先级19运行 . 我执行了以下命令 . 你可以看到pri是19.另外rtprio和pri有什么区别?我从redhat enterprise linux ver 6.3使用2.6内核 . 因为,这不是一个实时的linux,这行在代码 if(pthread_setschedparam(pthread_self(), SCHED_RR, ¶m))
中有效,因为我将调度程序设置为 SCHED_RR
ps -p 10834 -o pid,tid,class,rtprio,ni,pri,psr,pcpu,stat
PID TID CLS RTPRIO NI PRI PSR %CPU STAT
10834 10834 TS - 0 19 9 99.9 R+
void changePriority(int tPriority)
{
int policy;
struct sched_param param;
pthread_getschedparam(pthread_self(), &policy, ¶m);
param.sched_priority = tPriority;
if(pthread_setschedparam(pthread_self(), SCHED_RR, ¶m))
err_sys("error while setting thread priority to %d", tPriority);
}
1 回答
引用
PRI
与RTPRIO
,从man ps
逐字:可以使用
nice()
系统调用或nice
命令行工具设置PRI
.PRI
是进程_448038的优先级 . 对于Linux,这也为进程的非实时线程*设置了优先级 .来自
man 1 nice
:Niceness
和PRI
是同义词 .*实时线程是一个调度策略与
SCHED_OTHER
,SCHED_BATCH
和SCHED_IDLE
不同的线程,因为它有:SCHED_FIFO
和SCHED_RR
.RTPRIO
和调度策略可以通过OP中提到的功能设置 .保证调度策略提供至少32个不同的级别 . 使用
sched_get_priority_min
和sched_get_priority_max
确定已实施的范围 .