资源预览内容
第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
第9页 / 共11页
第10页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
/ stdafx.h : include file for standard system include files,/ or project specific include files that are used frequently, but/ are changed infrequently/#if !defined(AFX_STDAFX_H_57C8F7A3_80F8_4D89_8FF4_83D8673D5B32_INCLUDED_)#define AFX_STDAFX_H_57C8F7A3_80F8_4D89_8FF4_83D8673D5B32_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000/ TODO: reference additional headers your program requires here/AFX_INSERT_LOCATION/ Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif / !defined(AFX_STDAFX_H_57C8F7A3_80F8_4D89_8FF4_83D8673D5B32_INCLUDED_)/ 先来先服务.cpp : Defines the entry point for the console application./#include stdafx.h#include windows.h#include #include #include #include #include #include void Create_ProcInfo(); / 建立进程调度需要的数据void Display_ProcInfo(); / 显示当前系统全部进程的状态void Scheduler_FF();void Cpu_Sched();void IO_Sched();void NextRunProcess();void DisData();void DisResult();int RunPoint; / 运行进程指针,-1时为没有运行进程int WaitPoint; / 阻塞队列指针,-1时为没有阻塞进程int ReadyPoint; / 就绪队列指针,-1时为没有就绪进程long ClockNumber; / 系统时钟int ProcNumber; / 系统中模拟产生的进程总数int FinishedProc; / 系统中模拟产生的进程总数/进程信息结构struct ProcStruct int p_pid; / 进程的标识号 char p_state; / 进程的状态,C-运行 R-就绪 W-组塞 B-后备 F-完成 int p_rserial16; / 模拟的进程执行的CPU和I/O时间数据序列,间隔存储,0项存储有效项数 int p_pos; / 当前进程运行到的序列位置 int p_starttime; / 进程建立时间 int p_endtime; / 进程运行结束时间 int p_cputime; / 当前运行时间段进程剩余的需要运行时间 int p_iotime; / 当前I/O时间段进程剩余的I/O时间 int p_next; / 进程控制块的链接指针 proc10;/ 随机生成进程数量和每个CPU-I/O时间数据序列,进程数量控制在5到10之间, / 数据序列控制在6到12之间,CPU和I/O的时间数据值在5到15的范围 /void Create_ProcInfo(void )int s,i,j; srand(GetTickCount(); / 初始化随机数队列的种子ProcNumber=(float) rand() / 32767) * 5 + 5; / 随机产生进程数量510FinishedProc=0;for(i=0;iProcNumber;i+) / 生成进程的CPU-I/O时间数据序列 proci.p_pid=(float) rand() / 32767) * 1000;proci.p_state=B; / 初始都为后备状态s=(float) rand() / 32767) *6 + 6; / 产生的进程数据序列长度在612间proci.p_rserial0=s; / 第一项用于记录序列的长度for(j=1;j=s;j+) / 生成时间数据序列,数值在1030间proci.p_rserialj=(float) rand() / 32767) *10 + 5;/ 赋其他字段的值proci.p_pos=1;proci.p_starttime=(float) rand() / 32767) *49+1;proci.p_endtime=0; proci.p_cputime=proci.p_rserial1; proci.p_iotime=proci.p_rserial2; proci.p_next=-1; printf(n-n 建立了%2d 个进程数据序列nn, ProcNumber); DisData(); printf(nPress Any Key To Continue.); _getch() ; return ;/ 显示系统当前状态/void Display_ProcInfo(void) int i,n; system(cls) ; printf(n 当前系统模拟%2d 个进程的运行 时钟:%ldnn, ProcNumber,ClockNumber); printf(就绪指针=%d, 运行指针=%d, 阻塞指针=%dn,ReadyPoint,RunPoint,WaitPoint ); if(RunPoint!= -1) printf(当前运行的进程No.%d ID:%dn, RunPoint,procRunPoint.p_pid); printf(%6d,%6d,%6dn,procRunPoint.p_starttime,procRunPoint.p_rserialprocRunPoint.p_pos,procRunPoint.p_cputime); else printf(当前运行的进程ID:No Process Running !n); n=ReadyPoint; printf(nReady Process . n); while(n!=-1) / 显示就绪进程信息 printf(No.%d ID:%5d,%6d,%6d,%6dn,n,procn.p_pid,procn.p_starttime,procn.p_rserialprocn.p_pos,procn.p_cputime ); n=procn.p_next; n=WaitPoint; printf(nWaiting Process . n); while(n!=-1) / 显示阻塞进程信息 printf(No.%d ID:%5d,%6d,%6d,%6dn,n,procn.p_pid,procn.p_starttime,procn.p_rserialprocn.p_pos,procn.p_iotime); n=procn.p_next; printf(n= 后备进程 =n); for(i=0; iProcNumber; i+) if (proci.p_state=B) printf(No.%d ID:%5d,%6dn,i,proci.p_pid,proci.p_starttime); printf(n= 已经完成的进程 =n); for(i=0; iProcNumber; i+) if (proci.p_state=F) printf(No.%d ID:%5d,%6d,%6dn,i,proci.p_pid,proci.p_starttime,proci.p_endtime); /printf(n指针状态.n); /printf(就绪队列指针=%d, 运行指针=%d, 阻塞队列指针=%dn,ReadyPoint,RunPoint,WaitPoint );/ 显示模拟执行的结果/
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号