【多线程编程】线程调度策略及优先级

               

通过之前的学习我知道了当前 Linux 系统下任务调度策略主要有三种:

1、SCHED_OTHER:普通任务调度策略。

2、SCHED_FIFO:实时任务调度策略,先到先服务。一旦占用cpu则一直运行,直到有更高优先级任务到达或自己放弃。

3、SCHED_RR:实时任务调度策略,时间片轮转。当任务的时间片用完,系统将重新分配时间片,并置于就绪队列尾。放在队列尾

保证了所有具有相同优先级的RR任务的调度公平。


Linux 提供的有关任务调度策略及优先级的接口函数:


1、

// 首先了解 sched_param 结构体// In the current implementation, the structure contains only one field, sched_priority.  // The interpretation of param depends on the selected policystruct sched_param {
           int sched_priority;};




2、

int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param);int sched_getscheduler(pid_t pid);


The sched_setscheduler() system call sets both the scheduling policy and parameters for the thread whose ID is specified in pid.  

If pid equals zero, the scheduling policy and parameters of the calling thread will be set.

The sched_getscheduler() returns the current scheduling policy of the thread identified by pid.  If pid equals zero, the policy of the 

calling thread will be retrieved.


与上面函数类似的还有:

int sched_setparam(pid_t pid, const struct sched_param *param);int sched_getparam(pid_t pid, struct sched_param *param);



我们可以使

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值