linux时间片和优先度,Linux优先级时间片调度C++源码

【实例简介】Linux进程调度(基于优先级时间片调度算法)

【实例截图】

b35d90b951e61eebc07a2462e8e2906c.png

7bfeea5a07c1062442932de31f00891e.png

【核心代码】

int time()

{

float time_temp=0;

struct task_struct copy_PCB[MAX][MAX];//备份

for(int v=1; v<=temp; v )

{

for(int u=1;u<=P[v];u )

{

copy_PCB[v][u]=PCB[v][u];//对进程的初始化信息备份

}

}

time_temp=PCB[1][1].come_time;

for(int i=1;i<=temp;i )

{

while (PCB[i][P[i]].run_flag==0)

{

for(int j=1;j<=P[i];j )

{

if(PCB[i][j].come_time>time_temp)

{

time_temp=PCB[i][j].come_time;

}

if(PCB[i][j].run_flag==0)//该进程还未结束

{

if(PCB[i][j].start_flag==0) //该条件成立则说明,该进程是第一次执行,记录开始执行时间

{

PCB[i][j].run_begin_time=time_temp;

PCB[i][j].start_flag=1;

}

if(PCB[i][j].run_time/time_counter>1)//至少有两倍的时间片未执行

{

PCB[i][j].run_time=PCB[i][j].run_time-time_counter;

time_temp=time_temp time_counter;

}

else if(PCB[i][j].run_time-time_counter==0)

{

time_temp=time_temp time_counter;

PCB[i][j].run_end_time=time_temp;

PCB[i][j].run_flag=1;

PCB[i][j].run_time=copy_PCB[i][j].run_time;

}

else//仅剩下不足一倍的时间片

{

time_temp=time_temp PCB[i][j].run_time;

PCB[i][j].run_end_time=time_temp;

PCB[i][j].run_flag=1;

PCB[i][j].run_time=copy_PCB[i][j].run_time;

}

}

}

}

}

return 0;

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值