请输入您要查询的百科知识:

 

词条 sched_setscheduler
释义

设置调度策略

#include <sched.h>

int sched_setscheduler(pid_t pid, int policy,

const struct sched_param *param);

sched_setscheduler()函数将pid所指定进程的调度策略和调度参数分别设置为param指向的sched_param结构中指定的policy和参数。sched_param结构中的sched_priority成员的值可以为任何整数,该整数位于policy所指定调度策略的优先级范围内(含边界值)。policy参数的可能值在头文件中定义。

如果存在pid所描述的进程,将会为进程ID等于pid的进程设置调度策略和调度参数。

如果pid为零,将会为调用进程设置调度策略和调度参数。

如果进程pid含多个进程或轻量进程(即该进程是多进程的),此函数将影响进程中各个子进程。

更改其他进程的调度参数需要有相应的特权。调用进程必须具有相应的特权,或者是具有PRIV_RTSCHED权限的组的成员,猜能成功调用sched_setscheduler()。如果sched_setscheduler()函数成功地将pid所指定调度策略和调度参数分别设置为policy和结构param指定值 ,则该函数调用成功。

例子:更改调用进程以使用最强的FIFO优先级,如下所示:

#include <sched.h>

int main(int argc,char *argv[])

{

struct sched_param param;

int maxpri;

maxpri = sched_get_priority_max(SCHED_FIFO);//&raquo;&ntilde;&Egrave;&iexcl;×&icirc;&acute;ó&Ouml;&micro;

if(maxpri == -1)

{

perror("sched_get_priority_max() failed");

exit(1);

}

param.sched_priority = maxpri;

if (sched_setscheduler(getpid(), SCHED_FIFO, &param) == -1) //设置优先级

{

perror("sched_setscheduler() failed");

exit(1);

}

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/25 5:37:13