linux进程调度课程设计,操作系统课程设计进程调度模拟源代码.doc

253b171540df25e1b84436cbe50dfc72.gif操作系统课程设计进程调度模拟源代码.doc

experiment1.cpp Defines the entry point for the console application. include “stdio.h“ include “stdlib.h“ include “time.h“ typedef struct PCB int name; int runtime; int runedtime; int state; int killtime; int waitpoint; int waittime; struct PCB *next; PCB; define NUM 10 int mainint argc, char* argv int n0; int timeslice3; PCB *runqueueNULL; 运行队列 PCB *topNULL,*tailNULL,*temp; 就绪队列 PCB *top_waitNULL,*tail_waitNULL,*p; int i; srand10;给定随机数种子 srandinttimeNULL; fori0;inamei; temp-runtimerand201; temp-runedtime0; temp-nextNULL; temp-killtime0; temp-waitpointrandtemp-runtime1; temp-waittimerand201; ifi0 toptemp; tailtemp; else tail-nexttemp; tailtemp; printf“create name d, runtimed, runedtimed,killtimed, waitpointd,waittimedn“ ,tail-name,tail-runtime,tail-runedtime,tail-killtime,tail-waitpoint,tail-waittime; whiletopNULLtop_waitNULL iftopNULL goto flag; runqueuetop; toptop-next; runqueue-nextNULL;从就绪队列选一个节点,插入运行队列 runqueue-killtimetimeslice;计算消耗的时间 runqueue-runedtimerunqueue-runedtimerunqueue-killtime;计算总共运行时间 runqueue-runtimerunqueue-runtime-timeslice;计算剩余运行时间 ifrunqueue-runedtime-runqueue-waitpoint0 runqueue-killtimetimeslice-runqueue-runedtime-runqueue-waitpoint; runqueue-runedtimerunqueue-waitpoint; iftop_waitNULL判断阻塞队列是否为空 top_waitrunqueue; tail_waittop_wait;插入阻塞队列 else tail_wait-nextrunqueue; tail_waittail_wait-next;插入阻塞队列 printf“runtowait name d,runtimed,runedtimed,killtimedn“ ,runqueue-name,runqueue-runtime,runqueue-runedtime,runqueue-killtime; else ifrunqueue-runtimekilltime0; runqueue-runtime0; printf“kill name d, runtimed, runedtimed,killtimedn“ ,runqueue-name,runqueue-runtime,runqueue-runedtime,runqueue-killtime; n; deleterunqueue; 如果是 ,删除节点 else如果时间片结束后进程没有被杀死且不需要等待,插入就绪队列队尾 iftopNULL判断就绪队列是否为空 tail-nextrunqueue; tailtail-next; else toprunqueue; tailrunqueue; printf“running name d, runtimed, runedtimed,killtimedn“ ,runqueue-name,runqueue-runtime,runqueue-runedtime,runqueue-killtime; flag if top_waitNULL temptop_wait; whiletempNULL 扫描阻塞队列,是否存在等待时间已到的节点 printf“waiting name d waittimedn“,temp-name,temp-waittime; iftemp-waittimekilltime0; printf“waittorun name d,runtimed,runedtimedkilltimedn“ ,temp-name,temp-runtime,temp-runedtime,temp-killtime; iftopNULL判断就绪队列是否为空 tail-nexttemp; 插入就绪 队列 tailtail-next; iftemptop_wait top_waittop_wait-next; else iftop_wait-nextNULL ptop_wait; whilep-nexttemp pp-next; iftemptail_wait tail_waitp; p-nexttemp-next; tempp; 把节点从阻塞队列删除 tail-nextNULL; else toptemp; tailtemp; iftemptop_wait top_waittop_wait-next; else iftop_wait-nextNULL ptop_wait; whilep-nexttemp pp-next; iftemptail_wait tail_waitp; p-nexttemp-next; tempp; 把节点从阻塞队列删除 tail-nextNULL; else temp-waittimetemp-waittime-timeslice; 修改继续等待时间 temptemp-next; printf“所有 d个进程已执行完毕 n“,n; return 0;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值