ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:111.37KB ,
资源ID:18647127      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/18647127.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(处理机调度算法的实现文档格式.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

处理机调度算法的实现文档格式.docx

1、【实验内容】1 设定系统中有五个进程,每一个进程用一个进程控制块表示。2 输入每个进程的“优先数”和“要求运行时间”。3 为了调度方便,将五个进程按给定的优先数从大到小连成就绪队列。用一单元指出队列首进程,用指针指出队列的连接情况。4 处理机调度总是选队首进程运行。采用动态优先数算法,进程每运行一次优先数就减“1”,同时将运行时间减“1”。5 若某进程运行时间为零,则将其状态置为“结束”,且退出队列。6 运行所设计程序,显示或打印逐次被选中进程的进程名,以及进程控制块的动态变化过程。【实验步骤、过程】 1、程序流程图 2、程序代码/ Deal_ProcessDlg.cpp : implemen

2、tation file/#include stdafx.hDeal_Process.hDeal_ProcessDlg.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CAboutDlg dialog used for App About#define N 5/定义进程控制块typedef struct PCB int num; int prior; int request_time; char state;PCB;/定义全局变量PCB *pcb=new PCB5;

3、int count=0,_count=0;class CAboutDlg : public CDialogpublic: CAboutDlg();/ Dialog Data /AFX_DATA(CAboutDlg) enum IDD = IDD_ABOUTBOX ; /AFX_DATA / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support /AF

4、X_VIRTUAL/ Implementationprotected: /AFX_MSG(CAboutDlg) /AFX_MSG DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD) /AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAPBEGIN_MES

5、SAGE_MAP(CAboutDlg, CDialog) /AFX_MSG_MAP(CAboutDlg) / No message handlers /AFX_MSG_MAPEND_MESSAGE_MAP()/ CDeal_ProcessDlg dialogCDeal_ProcessDlg:CDeal_ProcessDlg(CWnd* pParent /*=NULL*/) : CDialog(CDeal_ProcessDlg:IDD, pParent) /AFX_DATA_INIT(CDeal_ProcessDlg) m_count1 = _T(); m_prior1 = 0; m_count

6、2 = _T( m_request_time1 = 0; m_prior2 = _T( m_request_time2 = _T( / Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CDeal_ProcessDlg: /AFX_DATA_MAP(CDeal_ProcessDlg) DDX_Control(pDX, IDC_Start, m_Start); DDX_Control(pDX, IDC_Co

7、nfirm, m_Confirm); DDX_Control(pDX, IDC_Request_Time1, m_Edit2); DDX_Control(pDX, IDC_Prior1, m_Edit1); DDX_Control(pDX, IDC_LIST_F, m_list_f); DDX_Control(pDX, IDC_LIST_W, m_list_w); DDX_Text(pDX, IDC_Count1, m_count1); DDX_Text(pDX, IDC_Prior1, m_prior1); DDX_Text(pDX, IDC_Count2, m_count2); DDX_T

8、ext(pDX, IDC_Request_Time1, m_request_time1); DDV_MinMaxInt(pDX, m_request_time1, 0, 100); DDX_Text(pDX, IDC_Prior2, m_prior2); DDX_Text(pDX, IDC_Request_Time2, m_request_time2);BEGIN_MESSAGE_MAP(CDeal_ProcessDlg, CDialog) /AFX_MSG_MAP(CDeal_ProcessDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDR

9、AGICON() ON_BN_CLICKED(IDC_Confirm, OnConfirm) ON_BN_CLICKED(IDC_Start, OnStart) ON_BN_CLICKED(IDC_Exit, OnExit)/ CDeal_ProcessDlg message handlersBOOL CDeal_ProcessDlg:OnInitDialog()OnInitDialog(); / Add About. menu item to system menu. / IDM_ABOUTBOX must be in the system command range. ASSERT(IDM

10、_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); / Set the icon for this dialog. The framework does this automatically / when the applications main window is not a dialog SetIcon(m_hIcon, TRUE); / Set big icon SetIco

11、n(m_hIcon, FALSE); / Set small icon / TODO: Add extra initialization here /添加自己的代码 m_Edit1.ShowWindow(SW_SHOW); m_Edit2.ShowWindow(SW_SHOW); m_Confirm.ShowWindow(SW_SHOW); m_Start.ShowWindow(SW_SHOW); UpdateWindow(); /提示用户进行初始化 m_count1.Format(%d,1); UpdateData(false); /首先设定列表控件风格可以整行选中,并具有作业线 DWORD

12、 style=m_list_w.GetExtendedStyle(); m_list_w.SetExtendedStyle(style|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); DWORD style_1=m_list_f.GetExtendedStyle(); m_list_f.SetExtendedStyle(style_1|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); /以下为插入几个列的列标题 CRect rect; m_list_w.GetClientRect(&rect); int nColInterval=r

13、ect.Width()/7; m_list_w.InsertColumn(0,进程编号,LVCFMT_LEFT,nColInterval*2); m_list_w.InsertColumn(1,优先数 m_list_w.InsertColumn(2,要求运行时间 m_list_w.InsertColumn(3,状态,LVCFMT_LEFT,rect.Width()-nColInterval*6); m_list_f.InsertColumn(0, m_list_f.InsertColumn(1, m_list_f.InsertColumn(2, m_list_f.InsertColumn(3,

14、 return TRUE; / return TRUE unless you set the focus to a controlOnSysCommand(UINT nID, LPARAM lParam) if (nID & 0xFFF0) = IDM_ABOUTBOX) CAboutDlg dlgAbout; dlgAbout.DoModal(); else CDialog:OnSysCommand(nID, lParam);/ If you add a minimize button to your dialog, you will need the code below/ to draw

15、 the icon. For MFC applications using the document/view model,/ this is automatically done for you by the framework.OnPaint() if (IsIconic() CPaintDC dc(this); / device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); / Center icon in client rectangle int cxIcon = Ge

16、tSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(& int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; / Draw the icon dc.DrawIcon(x, y, m_hIcon);OnPaint();/ The system calls this to obtain the cursor to display while the u

17、ser drags/ the minimized window.HCURSOR CDeal_ProcessDlg:OnQueryDragIcon() return (HCURSOR) m_hIcon;/初始化N个进程OnConfirm() Add your control notification handler code here UpdateData(true); pcbcount.num=count+1; pcbcount.prior=m_prior1; pcbcount.request_time=m_request_time1; pcbcount.state=W;/表示进程处于就绪状态

18、 /将进程信息显示在就绪进程列表中中 CString strItem; strItem.Format(_T(),count+1); m_list_w.InsertItem(count,strItem);/首先插入一行,其中的字符可以任意,也可以为空),m_prior1); m_list_w.SetItemText(count,1,strItem);/设置第二列数据,如此可以设置其它列的数据),m_request_time1); m_list_w.SetItemText(count,2,strItem); m_list_w.SetItemText(count,3,_T(W); if(countN

19、-1) m_count1.Format(,count+2); m_prior1=0; m_request_time1=0; UpdateData(false); /屏蔽初始化组件 m_Edit1.ShowWindow(SW_HIDE); m_Edit2.ShowWindow(SW_HIDE); m_Confirm.ShowWindow(SW_HIDE); MessageBox(初始化完成,系统中现有5个进程,点击“开始”按钮,模拟处理机调度 return; count+;/*理论上将N个进程按给定的优先数从大到小连成就绪队列,但实际上只需找到优先数最高的就绪进程*/int CDeal_Proc

20、essDlg:Get_Max_prior_ready_process() int i,j,max; for(i=0;iN;i+) if(pcbi.state=) max=i;break; if(i=5) max=i; for(j=max+1;jj+) if(pcbj.state= if(pcbmax.priorpcbj.prior) max=j; return max;Running() Sleep(500);/等待,表示运行了一个时间片 int temp; temp=Get_Max_prior_ready_process(); if(temp=N)系统内部的进程全部运行完毕! /屏蔽其他组件

21、 m_count2.Format( m_prior2.Format( m_request_time2.Format( /修改当前运行进程的PCB if(pcbtemp.request_time) pcbtemp.request_time-=1;/需要运行时间减1 pcbtemp.prior-=1;/优先数减1 /显示当前正在运行的进程信息 m_prior2.Format(,pcbtemp.prior); m_request_time2.Format(,pcbtemp.request_time); m_count2.Format(,temp+1); if(pcbtemp.request_time

22、=0) pcbtemp.state=F /将该进程信息在就绪进程表中删除 int _num=0; int nIndex; tagLVFINDINFOA info; CString strlist=_T( _num=m_list_w.GetItemCount(); info.flags=LVFI_PARTIAL|LVFI_STRING; for(int i=0;_num; strlist.Format(,pcbtemp.num); info.psz=strlist;/找到待删除的行 if(nIndex=m_list_w.FindItem(&info)!=-1) m_list_w.DeleteIt

23、em(nIndex); break; /将该进程加入到已完成进程列表中),pcbtemp.num); m_list_f.InsertItem(_count,strItem);),pcbtemp.prior); m_list_f.SetItemText(_count,1,strItem);),0); m_list_f.SetItemText(_count,2,strItem); m_list_f.SetItemText(_count,3,_T(F m_list_f.Update(_count); _count+; Running();OnStart() /屏蔽开始按钮 m_Start.ShowWindow(SW_HIDE);OnExit() OnOK(); 3、运行结果(1)初始化进程信息,显示到就绪进程列表控件中(2)点击开始按钮,模拟处理机调度,动态显示运行情况(3)将完成的进

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1