《操作系统课程设计》指导书Word文档下载推荐.docx
- 文档编号:18141735
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:19
- 大小:63.22KB
《操作系统课程设计》指导书Word文档下载推荐.docx
《《操作系统课程设计》指导书Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《《操作系统课程设计》指导书Word文档下载推荐.docx(19页珍藏版)》请在冰豆网上搜索。
。
boolbInMemoryFlag。
//该页是否在内存
intnFrameNo。
//内存的快号
intnDiskRelBlockNo。
//磁盘的相对块号<
可以随机给定)
intnNextPageNo。
//下一调进内存页的页号
boolbModifiedFlag。
//修改位<
//...
}。
classCProcess:
publicCObject//进程的信息
DECLARE_DYNCREATE(CProcess>
CProcess(>
voidInitProcessParameter(intno,intpagetotal,intruntime>
intGetOneLogicalAddress(>
//得到下一要访问的页的页号
voidAddressMapping(intLogicalAddress>
intnPID。
//进程标识符
charszProcessName[20]。
//进程名
intnControlNo。
intnStatus。
intnPageCountLogicalSpace。
//逻辑地址空间的页数
intnPageCountInMemory。
//调入内存的页数
intnRunTime。
//运行时间<
运行步数)
intnPageNoHead。
//调入内存的首页
intnPageNoTail。
//调入内存的末页
//其他信息,如就绪或阻塞队列指针----自己可以根据自己的能力与爱好进一步完善下去
CPage*PageTable。
intMaxFrameCount。
intGetOneRandDiskNo(>
//随机产生一个虚页在磁盘的相对块号
returnrand(>
%(1024*1024>
}
CPage:
:
CPage(>
bInMemoryFlag=0。
nFrameNo=0。
nDiskRelBlockNo=GetOneRandDiskNo(>
nNextPageNo=0。
bModifiedFlag=0。
IMPLEMENT_DYNCREATE(CPage,CObject>
CProcess:
CProcess(>
{
nPID=(int>
this。
nPageCountInMemory=0。
nStatus=0。
nPageNoHead=0。
nPageNoTail=0。
PageTable=NULL。
voidCProcess:
InitProcessParameter(intno,intpagetotal,intruntime>
sprintf(szProcessName,"
ProcName%1d"
no>
nControlNo=no。
nPageCountLogicalSpace=pagetotal。
nRunTime=runtime。
PageTable=newCPage[nPageCountLogicalSpace]。
//根据实际需要创建页表
intCProcess:
GetOneLogicalAddress(>
intran_num。
ran_num=rand(>
%nPageCountLogicalSpace。
returnran_num。
AddressMapping(intLogicalAddress>
intnIndexIn=LogicalAddress。
//正在访问到的页的页号
intnIndexOut。
intnFrameNoReused。
//
if(PageTable[nIndexIn].bInMemoryFlag==0>
//未装入内存
{
if(nPageCountInMemory<
MaxFrameCount>
//本进程使用的内存块数未达最大块数
{
PageTable[nIndexIn].nFrameNo=COsExamDlg:
AllocateMemoryFrame(nControlNo>
//请求分配一块
PageTable[nIndexIn].bInMemoryFlag=true。
//维护链表
if(nPageCountInMemory==0>
//第一个页面装入内存
{
PageTable[nIndexIn].nNextPageNo=-1。
this->
nPageNoHead=nIndexIn。
nPageNoTail=nIndexIn。
}
else
//刚装入的页面的Next指针设为-1<
终点)
PageTable[this->
nPageNoTail].nNextPageNo=nIndexIn。
nPageCountInMemory++。
}
else//本进程使用的内存块数已达最大块数
//淘汰一页
nIndexOut=this->
nPageNoHead。
nFrameNoReused=PageTable[nIndexOut].nFrameNo。
//暂存被重用的内存块的块号
this->
nPageNoHead=PageTable[nIndexOut].nNextPageNo。
//把首页设到原来的第二个顺序页
PageTable[nIndexOut].nFrameNo=-1。
//原来的页设成不在内存
PageTable[nIndexOut].bInMemoryFlag=false。
PageTable[nIndexIn].nFrameNo=nFrameNoReused。
//访问页装入腾出的块
//设为“已装入”
PageTable[nIndexIn].nNextPageNo=-1。
//刚访问的页面的Next指针设为-1<
PageTable[this->
//附加到链表
//设置为新的“链尾”
//
//设置内存映像的显示串
//。
}
else//访问地址对应的页已在内存
//直接访问
2设计使用上述数据结构来实现请求分页模拟系统
下面的例子是用VC的对话框应用程序来实现的测试或应用系统模型。
进程的推进由windows的线程来模拟的,这里进程的内容是由随机数产生运行轨迹。
intCOsExamDlg:
m_sMemoryFrameCount=120。
m_sOsFrameCount=40。
boolbMemoryBitmap[MAX_MEMORY_FRAME_COUNT]。
//内存空间管理的位示图
CStringcsMemoryBitmap。
//用于显示内存使用情况的字符串
intGetOneLogicalAddress(>
return0。
UINTBarryProcessThreadProc(LPVOIDpParam>
//模拟进程的线程函数
CProcess*pProcess=(CProcess*>
pParam。
if(pProcess==NULL||!
pProcess->
IsKindOf(RUNTIME_CLASS(CProcess>
>
return1。
//如果pObject无效,则返回1
//添加执行代码
CStringcsOutputInfo="
"
inti。
intLA。
for(i=0。
i<
nRunTime。
i++>
//执行每个操作步
//随机产生一个访问地址
LA=GetOneLogicalAddress(>
//地址变换--改变数据结构,改变用户界面
pProcess->
AddressMapping(LA>
csOutputInfo+="
M"
//构造显示页表信息的串
CWnd*pMainWnd。
pMainWnd=AfxGetMainWnd(>
switch(pProcess->
nControlNo>
case0:
pMainWnd->
GetDlgItem(IDC_STATIC_PROCESS0>
->
SetWindowText(csOutputInfo>
break。
case1:
GetDlgItem(IDC_STATIC_PROCESS1>
case2:
GetDlgItem(IDC_STATIC_PROCESS2>
case3:
GetDlgItem(IDC_STATIC_PROCESS3>
//延时
Sleep(1000>
//threadcompletedsuccessfully!
CProcess*ProcessPool。
voidCOsExamDlg:
OsInitialization(>
csMemoryBitmap="
MAX_MEMORY_FRAME_COUNT。
bMemoryBitmap[i]=false。
csMemoryBitmap+="
"
AllocateMemoryFrame(intnProcessNo>
intnFrameNoStart。
nFrameNoStart=m_sOsFrameCount+rand(>
%(m_sMemoryFrameCount-m_sOsFrameCount>
while(bMemoryBitmap[nFrameNoStart]==true>
nFrameNoStart=nFrameNoStart+1。
if(nFrameNoStart==m_sMemoryFrameCount>
nFrameNoStart=m_sOsFrameCount。
returnnFrameNoStart。
COsExamDlg:
COsExamDlg(CWnd*pParent/*=NULL*/>
:
CDialog(COsExamDlg:
IDD,pParent>
//{{AFX_DATA_INIT(COsExamDlg>
m_nProcessCount=0。
m_nMemoryFrameCount=0。
m_nOsFrameCount=0。
m_nMaxFrameForOneProcess=0。
//}}AFX_DATA_INIT
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp(>
LoadIcon(IDR_MAINFRAME>
m_nProcessCount=3。
m_nMaxFrameForOneProcess=16。
m_nMemoryFrameCount=64。
m_nOsFrameCount=16。
DoDataExchange(CDataExchange*pDX>
CDialog:
DoDataExchange(pDX>
//{{AFX_DATA_MAP(COsExamDlg>
DDX_Text(pDX,IDC_EDIT_PROCESS_COUNT,m_nProcessCount>
DDX_Text(pDX,IDC_EDIT_MEMORY_FRAME_COUNT,m_nMemoryFrameCount>
DDV_MinMaxInt(pDX,m_nMemoryFrameCount,64,128>
DDX_Text(pDX,IDC_EDIT_OS_FRAME_COUNT,m_nOsFrameCount>
DDV_MinMaxInt(pDX,m_nOsFrameCount,16,32>
DDX_Text(pDX,IDC_EDIT_MAX_FRAME_COUNT_PER_PROCESS,m_nMaxFrameForOneProcess>
DDV_MinMaxInt(pDX,m_nMaxFrameForOneProcess,4,16>
//}}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(COsExamDlg,CDialog>
//{{AFX_MSG_MAP(COsExamDlg>
ON_WM_SYSCOMMAND(>
ON_WM_PAINT(>
ON_WM_QUERYDRAGICON(>
ON_BN_CLICKED(IDC_BUTTON_ACCEPT,OnButtonAccept>
ON_BN_CLICKED(IDC_BUTTON_SIMU,OnButtonSimu>
//}}AFX_MSG_MAP
END_MESSAGE_MAP(>
/////////////////////////////////////////////////////////////////////////////
//COsExamDlgmessagehandlers
BOOLCOsExamDlg:
OnInitDialog(>
//Add"
About..."
menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&
0xFFF0>
==IDM_ABOUTBOX>
ASSERT(IDM_ABOUTBOX<
0xF000>
CMenu*pSysMenu=GetSystemMenu(FALSE>
if(pSysMenu!
=NULL>
CStringstrAboutMenu。
strAboutMenu.LoadString(IDS_ABOUTBOX>
if(!
strAboutMenu.IsEmpty(>
pSysMenu->
AppendMenu(MF_SEPARATOR>
AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu>
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'
smainwindowisnotadialog
SetIcon(m_hIcon,TRUE>
//Setbigicon
SetIcon(m_hIcon,FALSE>
//Setsmallicon
//TODO:
Addextrainitializationhere
GetDlgItem(IDC_EDIT_PAGE_COUNT0>
SetWindowText("
12"
GetDlgItem(IDC_EDIT_PAGE_COUNT0>
GetDlgItem(IDC_EDIT_RUN_TIME0>
GetDlgItem(IDC_EDIT_PAGE_COUNT1>
8"
GetDlgItem(IDC_EDIT_RUN_TIME1>
GetDlgItem(IDC_EDIT_PAGE_COUNT2>
16"
GetDlgItem(IDC_EDIT_RUN_TIME2>
GetDlgItem(IDC_EDIT_PAGE_COUNT3>
9"
GetDlgItem(IDC_EDIT_RUN_TIME3>
srand(time(0>
returnTRUE。
//returnTRUEunlessyousetthefocustoacontrol
OnSysCommand(UINTnID,LPARAMlParam>
if((nID&
CAboutDlgdlgAbout。
dlgAbout.DoModal(>
else
CDialog:
OnSysCommand(nID,lParam>
//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
//thisisautomaticallydoneforyoubytheframework.
OnPaint(>
if(IsIconic(>
CPaintDCdc(this>
//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,(WPARAM>
dc.GetSafeHdc(>
0>
//Centericoninclientrectangle
intcxIcon=GetSystemMetrics(SM_CXICON>
intcyIcon=GetSystemMetrics(SM_CYICON>
CRectrect。
GetClientRect(&
rect>
intx=(rect.Width(>
-cxIcon+1>
/2。
inty=(rect.Height(>
-cyIcon+1>
//Drawtheicon
dc.DrawIcon(x,y,m_hIcon>
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统课程设计 操作系统 课程设计 指导书