1、实验一 进程管理一、实验目的通过程序的编写加强对进程概念的理解。二、实验仪器1、PC兼容机2、Windows、DOS系统3、C或C+语言三、实验原理通过C或C+语言创建新的进程;查看运行进程;换出某个进程;杀死运行进程;进程之间通信以及进程调度等功能。四、实验内容与步骤1、创建新的进程;查看当前运行进程;换出某个进程(中级调度);杀死运行进程。2、进程之间的通信功能:消息缓冲队列机制。3、用优先权(优先数)算法和时间片轮转算法对五个进程进行调度。提示:1、PCB(进程控制块)结构通常包括以下信息:进程名,进程优先权(优先数),轮转时间片,进程所需要的CPU服务时间,进程的状态,当前队列指针等。
2、PCB结构的内容可以根据实际实验需要作适当的增删。2、每个进程可有三个状态,并假设初始状态为就绪状态。为了便于处理,程序中的某进程运行时间以秒为单位计算。各进程的优先数及进程需运行的时间的初始值均由用户给定。在优先权(优先数)算法中,每个进程的优先数的初始值为(50减去运行时间),进程每执行一次,优先数减3,CPU已运行时间数加1,进程还需要的时间数减1。对于遇到优先数一致的情况,采用先来先服务策略解决。在时间片轮转算法中,采用固定时间片,即:进程每执行一次,执行一个CPU时间片,1个时间片包含2秒,一个时间片结束时,进程已使用CPU时间数加2,进程还需要的CPU时间数减2,如还有任务未完成需
3、要重新到就绪队列末尾排队。如果进程在一个时间片的结束之前完成任务离开系统,剩余的时间片送给下一个就绪进程使用,这个就绪进程用完上一个进程剩余的时间片后,进入自己的另一个完整时间片继续执行。五、实验结果范例实验运行结果1:* 进程演示系统 * 1.创建新的进程 2.查看运行进程 3.换出某个进程 4.杀死运行进程 5.进程之间通信 6.进程调度7.退出系统 *请选择(17)然后根据你选择的不同,出现不同的结果。实验运行结果2:在进程调度中,若选择了优先权调度算法,则进一步显示:INPUT NAME AND NEEDTIMEA1 2A2 3A3 4A4 2A5 4OUTPUT OF PRIORIT
4、Y:CPUTIME:1NAME CPUTIME NEEDTIME PRIORITY STATE A1 1 1 45 working A2 0 3 47 ready A3 0 4 46 ready A4 0 2 48 ready A5 0 4 46 readyCPUTIME:2NAME CPUTIME NEEDTIME PRIORITY STATE A1 1 1 45 ready A2 0 3 47 ready A3 0 4 46 ready A4 1 1 45 working A5 0 4 46 readyCPUTIME:3NAME CPUTIME NEEDTIME PRIORITY STAT
5、E A1 1 1 45 ready A2 1 2 44 working A3 0 4 46 ready A4 1 1 45 ready A5 0 4 46 readyCPUTIME:4 NAME CPUTIME NEEDTIME PRIORITY STATE A1 1 1 45 ready A2 1 2 44 ready A3 1 3 43 working A4 1 1 45 ready A5 0 4 46 ready注:当进程执行完后,CPUTIME不再增加,其优先权也不再计算。因为程序执行完成,就放弃CPU,退出系统。CPUTIME:5NAME CPUTIME NEEDTIME PRIOR
6、ITY STATE A1 1 1 45 ready A2 1 2 44 ready A3 1 3 43 ready A4 1 1 45 ready A5 1 3 43 workingCPUTIME:6NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 1 2 44 ready A3 1 3 43 ready A4 1 1 45 ready A5 1 3 43 readyCPUTIME:7NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 1 2 44 ready A3 1
7、 3 43 ready A4 2 0 42 finish A5 1 3 43 readyCPUTIME:8NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 2 1 41 working A3 1 3 43 ready A4 2 0 42 finish A5 1 3 43 readyCPUTIME:9NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 2 1 41 ready A3 2 2 40 working A4 2 0 42 finish A5 1 3 43 rea
8、dyCPUTIME:10NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 2 1 41 ready A3 2 2 40 ready A4 2 0 42 finish A5 2 2 40 workingCPUTIME:11NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 3 0 38 finish A3 2 2 40 ready A4 2 0 42 finish A5 2 2 40 readyCPUTIME:12NAME CPUTIME NEEDTIME PRIORIT
9、Y STATE A1 2 0 42 finish A2 3 0 38 finish A3 3 1 37 working A4 2 0 42 finish A5 2 2 40 readyCPUTIME:13NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 3 0 38 finish A3 3 1 37 ready A4 2 0 42 finish A5 3 1 37 workingCPUTIME:14NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 3 0 38 fin
10、ish A3 4 0 34 finish A4 2 0 42 finish A5 3 1 37 readyCPUTIME:15NAME CPUTIME NEEDTIME PRIORITY STATE A1 2 0 42 finish A2 3 0 38 finish A3 4 0 34 finish A4 2 0 42 finish A5 4 0 34 finish时间片轮转调度算法演示:INPUT NAME AND NEEDTIMEA1 2A2 3A3 4A4 2A5 4CPUTIME:1NAME CPUTIME NEEDTIME STATE A1 1 1 working A2 0 3 re
11、ady A3 0 4 ready A4 0 2 ready A5 0 4 readyCPUTIME:2NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 0 3 ready A3 0 4 ready A4 0 2 ready A5 0 4 readyCPUTIME:3NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 1 2 working A3 0 4 ready A4 0 2 ready A5 0 4 readyCPUTIME:4NAME CPUTIME NEEDTIME STATE A1 2 0 finish A
12、2 2 1 working A3 0 4 ready A4 0 2 ready A5 0 4 readyCPUTIME:5NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 2 1 ready A3 1 3 working A4 0 2 ready A5 0 4 ready CPUTIME:6NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 2 1 ready A3 2 2 working A4 0 2 ready A5 0 4 readyCPUTIME:7NAME CPUTIME NEEDTIME STATE A1
13、 2 0 finish A2 2 1 ready A3 2 2 ready A4 1 1 working A5 0 4 readyCPUTIME:8NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 2 1 ready A3 2 2 ready A4 2 0 finish A5 0 4 readyCPUTIME:9NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 2 1 ready A3 2 2 ready A4 2 0 finish A5 1 3 workingCPUTIME:10NAME CPUTIME NEED
14、TIME STATE A1 2 0 finish A2 2 1 ready A3 2 2 ready A4 2 0 finish A5 2 2 workingCPUTIME:11NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 3 0 finish A3 2 2 ready A4 2 0 finish A5 2 2 readyCPUTIME:12NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 3 0 finish A3 3 1 working A4 2 0 finish A5 2 2 readyCPUTIME:1
15、3NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 3 0 finish A3 4 0 finish A4 2 0 finish A5 2 2 readyCPUTIME:14NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 3 0 finish A3 4 0 finish A4 2 0 finish A5 3 1 workingCPUTIME:15NAME CPUTIME NEEDTIME STATE A1 2 0 finish A2 3 0 finish A3 4 0 finish A4 2 0 finish A5 4 0 finish六、实验验收要求及成绩评定本学期最后一次实验课结束之前,在实验室给任课教师演示实验的运行过程和结果,讲解程序的详细编写过程。