【实例简介】Linux进程调度(基于优先级时间片调度算法)
【实例截图】
【核心代码】
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;
}