2022年操作系统进程调度算法模拟__MFC实现 .pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年操作系统进程调度算法模拟__MFC实现 .pdf》由会员分享,可在线阅读,更多相关《2022年操作系统进程调度算法模拟__MFC实现 .pdf(18页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、#include windows.h #include windowsx.h #include tchar.h #include strsafe.h #include resource.h #pragma warning(disable:4312) #pragma warning(disable:4244) #define EDITLEN 20 #define RR 2 / 时间片#define chHANDLE_DLGMSG(hWnd, message, fn) case (message): return (SetDlgMsgResult(hWnd, uMsg, HANDLE_#messa
2、ge(hWnd), (wParam), (lParam), (fn) struct ProcInfo int procID; / 进程 ID float arriveT; / 达到时间float serverT; / 服务时间float remainT; / 剩余运行时间float lastrunT; / 上次运行时间float runT; / 运行时间总和float priority; / 优先级,高响应比优先调度算法时初始为1,其他算法未用到,初始为 0 struct ProcInfo *next; / 下一结点 *startProc,*endProc; HWND hWnd; /* 检查
3、6 个进程的到达时间和服务时间是否已经全部输入已经全部输入返回TRUE,否则返回FALSE */ bool CheckEdits() wchar_t strEDITLEN; for (int i=IDC_A1;i=IDC_F1;i+=5) GetDlgItemText(hWnd,i,str,EDITLEN); if (lstrcmp(str,_T(0) = 0) return false; GetDlgItemText(hWnd,i+1,str,EDITLEN); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 -
4、 - - - - - - 第 1 页,共 18 页 - - - - - - - - - if (lstrcmp(str,_T(0) = 0 ) return false; return true; /* 计算平均周转时间和平均带权周转时间,并显示*/ void ShowEdits() float zzsj=0,pjzz=0; wchar_t str10; for (int i=IDC_A4;i=IDC_F4;i+=5) GetDlgItemText(hWnd,i,str,10); zzsj += _wtof(str); GetDlgItemText(hWnd,i+1,str,10); pjzz
5、 += _wtof(str); StringCchPrintf(str,10,_T(%f),zzsj/6); SetDlgItemText(hWnd,IDC_TIME1,str); StringCchPrintf(str,10,_T(%f),pjzz/6); SetDlgItemText(hWnd,IDC_TIME2,str); /* 清除所有编辑框的内容*/ void ClearEdits() for (int i=IDC_A1;inext = node; endProc = node; if (startProc-next = NULL) startProc-next = endProc;
6、 /* 移除链表头结点*/ void RemoveNode() if (startProc != NULL) float finishT; wchar_t str10; ProcInfo *tmp = startProc; if (startProc-next != NULL) startProc = startProc-next; startProc-lastrunT = tmp-lastrunT+tmp-remainT; else startProc = endProc = NULL; finishT = tmp-lastrunT+tmp-remainT; StringCchPrintf(
7、str,10,_T(%f),finishT); SetDlgItemText(hWnd,IDC_A3+5*tmp-procID,str); StringCchPrintf(str,10,_T(%f),finishT-tmp-arriveT); SetDlgItemText(hWnd,IDC_A4+5*tmp-procID,str); StringCchPrintf(str,10,_T(%f),(finishT-tmp-arriveT)/(float)tmp-serverT); SetDlgItemText(hWnd,IDC_A5+5*tmp-procID,str); delete tmp; /
8、* 当链表头结点被抢占或时间片到时,将头结点移到尾结点参数: moreT 为头结点运行到被抢占或时间片到的时间间隔名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 18 页 - - - - - - - - - */ void ChangeNode(int moreT) if (startProc != NULL) if (startProc-next != NULL) ProcInfo *tmp = startProc; startProc = startProc-next
9、; tmp-next = NULL; tmp-runT += moreT; tmp-remainT -= moreT; endProc-next = tmp; endProc = tmp; startProc-lastrunT = tmp-lastrunT+moreT; else startProc-lastrunT += moreT; startProc-runT += moreT; startProc-remainT -= moreT; /* 先到先服务调度算法*/ void AlgoFCFS(int *arrive,int *server) int procNum = 6; int in
10、dex = 0; ProcInfo *node; startProc = endProc = NULL; while (procNum) if (startProc != NULL) / 直接将每个进程插入链表,链表中每个结点按顺序运行while (indexprocID = index; node-arriveT = arriveindex; node-serverT = serverindex; node-remainT = serverindex; node-lastrunT = arriveindex; node-runT = 0; node-priority = 0; 名师资料总结
11、- - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 18 页 - - - - - - - - - node-next = NULL; index+; InsertNode(node); RemoveNode(); procNum-; else if (indexprocID = index; node-arriveT = arriveindex; node-serverT = serverindex; node-remainT = serverindex; node-lastrunT =
12、arriveindex; node-runT = 0; node-priority = 0; node-next = NULL; index+; InsertNode(node); else break; /* 短进程优先调度算法*/ void AlgoSJF(int *arrive,int *server) int procNum = 6; int index = 0; float minremainT; ProcInfo *node,*tmp,*seize,*mid,*tmp2; startProc = endProc = NULL; while (procNum) if (startPr
13、oc != NULL) tmp = seize = startProc; minremainT = startProc-remainT; / 查看链表中是否有剩余运行时间比头结点小的进程,如果有存入最小运行名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 18 页 - - - - - - - - - 时间while (tmp=tmp-next) != NULL) if (tmp-remainT remainT; seize = tmp; else if (minremain
14、T remainT & tmp-remainT = minremainT) if (tmp-arriveT arriveT) seize = tmp; while (index6) / 查看在头结点被短进程抢占,或运行结束时,是否有新进程到达if (arriveindex lastrunT+minremainT) node = new ProcInfo; node-procID = index; node-arriveT = arriveindex; node-serverT = serverindex; node-remainT = serverindex; node-lastrunT =
15、arriveindex; node-runT = 0; node-priority = 0; node-next = NULL; index+; InsertNode(node); / 当有新进程到达时,根据剩余运行时间插入到链表中mid = NULL; tmp = startProc; while (tmp-next != endProc) if (tmp-next-remainT endProc-remainT) mid = tmp; break; tmp = tmp-next; if (mid != NULL) tmp = startProc-next; while (tmp-next
16、!= NULL) if (tmp-next = endProc) tmp2 = endProc; tmp-next = NULL; endProc = tmp; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 18 页 - - - - - - - - - tmp2-next = mid-next; mid-next = tmp2; break; tmp = tmp-next; / 查看刚插入的结点的剩余运行时间是否小于最小剩余时间if (node-remainT rema
17、inT; seize = node; else if (minremainT remainT & node-remainT = minremainT) if (node-arriveT arriveT) seize = node; else break; / 当 seize仍为头结点时,表示没有比头结点更小的剩余运行时间,故移除头结点if (seize = startProc) RemoveNode(); procNum-; else / 否则,将抢占进程移到头结点之后,并更改结点tmp = startProc; while (tmp != NULL) if (tmp-next = seize
18、) tmp-next = seize-next; if (seize = endProc) endProc = tmp; break; tmp = tmp-next; seize-next = startProc-next; if (startProc = endProc) endProc = seize; startProc-next = seize; ChangeNode(minremainT); else 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 18 页 -
19、 - - - - - - - - if (indexprocID = index; node-arriveT = arriveindex; node-serverT = serverindex; node-remainT = serverindex; node-lastrunT = arriveindex; node-runT = 0; node-priority = 0; node-next = NULL; index+; InsertNode(node); else break; /* 高响应比优先调度算法*/ void AlgoHRP(int *arrive,int *server) i
20、nt procNum=6; int index=0; float waitT,minwaitT,waitT2,lastwaitT; ProcInfo *node,*tmp,*seize,*second; float prio=0,stmp; startProc = endProc = NULL; while(procNum) if (startProc != NULL) tmp = seize = second = startProc; minwaitT = startProc-remainT; / 计算在头结点剩余时间内,是否有进程的优先级超过头结点,如果有,取最先超过头结点的进程为抢占进程
21、while(tmp=tmp-next) != NULL) waitT = (startProc-priority-1)*tmp-serverT+0.1; / 计算超过头结点的最小等待时间lastwaitT = waitT-(startProc-lastrunT-tmp-arriveT-tmp-runT); / 计算头结点运行期间还需要等待的时间if (lastwaitT priority = waitT/tmp-serverT+1; seize = tmp; else if (minwaitT remainT & lastwaitT = minwaitT) / 当等于最小时间时,服务时间越小,
22、优先级越高if (tmp-serverT serverT) tmp-priority = waitT/tmp-serverT+1; seize = tmp; else if (tmp-serverT = seize-serverT) / 当等于最小时间,服务时间也相同时,先到达者优先if (tmp-arriveT arriveT) tmp-priority = waitT/tmp-serverT+1; seize = tmp; else if (minwaitT = startProc-remainT) / 当头结点剩余时间内,没有进程的优先级抢占时,计算优先级第二高的进程waitT2 = s
23、tartProc-lastrunT-tmp-arriveT-tmp-runT+startProc-remainT; stmp = waitT2/tmp-serverT+1; if (stmpprio) tmp-priority = prio = stmp; second = tmp; while (index6) / 查看在头结点的剩余时间内,或被抢占的时间间隔内,是否有进程到达if (arriveindex lastrunT+minwaitT) node = new ProcInfo; node-procID = index; node-arriveT = arriveindex; node
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年操作系统进程调度算法模拟_MFC实现 2022 操作系统 进程 调度 算法 模拟 _MFC 实现
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内