C先来先服务算法

上传人:s9****2 文档编号:431355825 上传时间:2023-12-22 格式:DOC 页数:11 大小:70.50KB
返回 下载 相关 举报
C先来先服务算法_第1页
第1页 / 共11页
C先来先服务算法_第2页
第2页 / 共11页
C先来先服务算法_第3页
第3页 / 共11页
C先来先服务算法_第4页
第4页 / 共11页
C先来先服务算法_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《C先来先服务算法》由会员分享,可在线阅读,更多相关《C先来先服务算法(11页珍藏版)》请在金锄头文库上搜索。

1、/ 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

2、_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_)/

3、 先来先服务.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 NextRunPro

4、cess();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

5、-就绪 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、据序列控制在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=(f

7、loat) 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_io

8、time=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, 阻塞指

9、针=%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

10、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,pro

11、cn.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 );/ 显示模拟执行的结果/

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号