版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、計(jì)算機(jī)科學(xué)與工程學(xué)院實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)課程名稱操作系統(tǒng)實(shí)驗(yàn)實(shí)驗(yàn)成績(jī)專業(yè)計(jì)算機(jī)科學(xué)與技術(shù)班級(jí)1507班指導(dǎo)教師簽字學(xué)號(hào)姓名羅藝博實(shí)驗(yàn)報(bào)告批改時(shí)間實(shí)驗(yàn)項(xiàng)目目錄1. 實(shí)驗(yàn)一 熟悉Linux系統(tǒng)2. 實(shí)驗(yàn)二 進(jìn)程狀態(tài)3. 實(shí)驗(yàn)三 進(jìn)程同步和通信4. 實(shí)驗(yàn)四 進(jìn)程的管道通信5. 實(shí)驗(yàn)五 頁(yè)面置換算法實(shí)驗(yàn)報(bào)告正文實(shí)驗(yàn)一 熟悉Linux系統(tǒng)一、 實(shí)驗(yàn)?zāi)康氖煜ず驼莆誏inux系統(tǒng)基本命令,熟悉Linux編程環(huán)境,為以后的實(shí)驗(yàn)打下基礎(chǔ)。二、 實(shí)驗(yàn)原理基于linux系統(tǒng)的基礎(chǔ)操作三、 實(shí)驗(yàn)內(nèi)容(源碼、注釋、基礎(chǔ)內(nèi)容、擴(kuò)展點(diǎn)等)啟動(dòng)、退出、ls(顯示目錄內(nèi)容)、cp(文件或目錄的復(fù)制)、mv(文件、目錄更名或移動(dòng))、rm
2、(刪除文件或目錄)、mkdir(創(chuàng)建目錄)、rmdir(刪除空目錄)、cd(改變工作目錄)C語(yǔ)言編輯、編譯四、 實(shí)驗(yàn)結(jié)果(截圖)ls mkdir:cd:rmdir:實(shí)驗(yàn)二 進(jìn)程狀態(tài)一、 實(shí)驗(yàn)?zāi)康淖孕芯幹颇M程序,通過形象化的狀態(tài)顯示,使學(xué)生理解進(jìn)程的概念、進(jìn)程之間的狀態(tài)轉(zhuǎn)換及其所帶來(lái)的PCB內(nèi)容 、組織的變化,理解進(jìn)程與其PCB間的一一對(duì)應(yīng)關(guān)系。二、 實(shí)驗(yàn)原理1.進(jìn)程在內(nèi)存中存在三種基本狀態(tài):就緒態(tài)、執(zhí)行態(tài)、阻塞態(tài)2.三種狀態(tài)在滿足某種條件時(shí)會(huì)發(fā)生轉(zhuǎn)換:就緒運(yùn)行:調(diào)度程序選擇一個(gè)新的進(jìn)程運(yùn)行運(yùn)行就緒:運(yùn)行進(jìn)程用完了時(shí)間片運(yùn)行進(jìn)程被中斷,因?yàn)橐桓邇?yōu)先級(jí)進(jìn)程處于就緒狀態(tài)運(yùn)行阻塞:當(dāng)一進(jìn)程等待某一事
3、件的發(fā)生時(shí),如請(qǐng)求系統(tǒng)服務(wù); 初始化I/O 且必須等待結(jié)果; 無(wú)新工作可做; 等待某一進(jìn)程提供輸入 (IPC)阻塞就緒:當(dāng)所等待的事件發(fā)生時(shí)三、 實(shí)驗(yàn)內(nèi)容(源碼、注釋、基礎(chǔ)內(nèi)容、擴(kuò)展點(diǎn)等)#include #include #include #include /for sort in vectorusing namespace std;class Pro /process classpublic: char name; string status;vector ru,re,bl; /ru-running,re-ready,bl-blocked/function declarationint h
4、elloUI();int iniQ();int showPCB();int ruTOre();int ruTObl();int blTOre();int neTOre();int ruTOex();int helloUI() /start UI cout Hello!Welcome to come back. endl; cout #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# endl; cout endl; cout endl; return 0;int iniQ() /initialize the process int i; cout Please en
5、ter processes names and their status. endl; cout endl; for(i=0; i5; i+) /15 process a to o Pro process; char nam; string sta; cout Please enter i processes names. nam; = nam; cout Please enter processes status. endl; cout Status contains r1(running),r2(ready) and b(blocked). sta; proces
6、s.status = sta; if(sta = r1) /judge which status if(ru.size()1) ru.push_back(process); cout yes endl; else cout Error! endl; else if(sta = r2) re.push_back(process); else if(sta = b) bl.push_back(process); else cout Error! endl; cout endl; cout endl; showPCB(); return 0;int showPCB() int i; cout run
7、ning:; for(i=0; iru.size(); i+) cout ,; cout endl; cout ready:; for(i=0; ire.size(); i+) cout ,; cout endl; cout blocked:; for(i=0; ibl.size(); i+) cout ,; cout endl; return 0;int ruTOre() if(!ru.empty() /runningQueue is being used. re.push_back(ru.front(); /runnings first
8、 process go to readylast ru.erase(ru.begin(); /delete runnings first process ru.push_back(re.front(); re.erase(re.begin(); else cout Error in ruTOre endl; showPCB(); return 0;int ruTObl() if(!ru.empty() /runningQueue is being used. bl.push_back(ru.front(); ru.erase(ru.begin(); if(!re.empty() ru.push
9、_back(re.front(); re.erase(re.begin(); else cout Error in ruTObl1. endl; else cout Error in ruTObl2. running ru.push_back(re.front(); re.erase(re.begin(); else cout Error in blTOre endl; showPCB(); return 0;int neTOre() int i; cout Please enter processes names and their status. endl; cout endl; Pro
10、process; char nam; string sta; cout Please enter processes names. nam; = nam; process.status = r2; re.push_back(process); cout endl; cout endl; if(ru.empty() ru.push_back(re.front(); re.erase(re.begin(); showPCB(); return 0;int ruTOex() if(!ru.empty() /runningQueue is being used. ru.era
11、se(ru.begin(); if(!re.empty() ru.push_back(re.front(); re.erase(re.begin(); else cout Error in ruTOex1. endl; else cout Error in ruTOex2. endl; showPCB(); return 0;int main() int act; /choose action helloUI(); cout Please initialize the process. endl; iniQ(); while(1) cout endl; cout Please select t
12、he action to take. endl; cout ready endl; cout blocked endl; cout ready endl; cout ready endl; cout exit act; if(act = 2) ruTOre(); else if(act = 3) ruTObl(); else if(act = 4) blTOre(); else if(act = 5) neTOre(); else if(act = 6) ruTOex(); else cout Error in select.endl; cout # endl; cout endl; retu
13、rn 0;拓展點(diǎn):五狀態(tài)模型四、 實(shí)驗(yàn)結(jié)果(截圖)創(chuàng)建進(jìn)程:狀態(tài) runningready:狀態(tài) runningblocked:狀態(tài) blockedready:創(chuàng)建新進(jìn)程:情況一 有進(jìn)程正在運(yùn)行情況二 無(wú)進(jìn)程正在運(yùn)行終止進(jìn)程:實(shí)驗(yàn)三 進(jìn)程同步和通信一、實(shí)驗(yàn)?zāi)康恼{(diào)試、修改、運(yùn)行模擬程序,通過形象化的狀態(tài)顯示,使學(xué)生理解進(jìn)程的概念,了解同步和通信的過程,掌握進(jìn)程通信和同步的機(jī)制,特別是利用緩沖區(qū)進(jìn)行同步和通信的過程。通過補(bǔ)充新功能,使學(xué)生能靈活運(yùn)用相關(guān)知識(shí),培養(yǎng)創(chuàng)新能力。二、 實(shí)驗(yàn)原理假定.緩沖區(qū)可以容納8個(gè)數(shù)據(jù);因?yàn)榫彌_區(qū)是有限的,因此當(dāng)其滿了時(shí)生產(chǎn)者進(jìn)程應(yīng)該等待;當(dāng)消費(fèi)者取走一個(gè)數(shù)據(jù)后,應(yīng)喚醒
14、正在等待的生產(chǎn)者進(jìn)程;當(dāng)緩沖區(qū)空時(shí),消費(fèi)者進(jìn)程應(yīng)該等待;當(dāng)生產(chǎn)者向緩沖區(qū)放入了一個(gè)數(shù)據(jù)時(shí),應(yīng)喚醒正在等待的消費(fèi)者進(jìn)程。這就是生產(chǎn)者和消費(fèi)者之間的同步三、 實(shí)驗(yàn)內(nèi)容(源碼、注釋、基礎(chǔ)內(nèi)容、擴(kuò)展點(diǎn)等)基礎(chǔ)內(nèi)容:編寫程序使其模擬兩個(gè)進(jìn)程,即生產(chǎn)者(producer)進(jìn)程和消費(fèi)者(Consumer)進(jìn)程工作;生產(chǎn)者每次產(chǎn)生一個(gè)數(shù)據(jù),送入緩沖區(qū)中;消費(fèi)者每次從緩沖區(qū)中取走一個(gè)數(shù)據(jù)。每次寫入和讀出數(shù)據(jù)時(shí),都將讀和寫指針加一。當(dāng)指針到達(dá)緩沖區(qū)尾,重新將指針退回起點(diǎn);/*/* PROGRAM NAME: PRODUCER_CONSUMER */* This program simulates two proc
15、esses, producer which */* continues to produce message and put it into a buffer */* implemented by PIPE, and consumer which continues to get */* message from the buffer and use it. */* The program also demonstrates the synchronism between */* processes and uses of PIPE. */*/#include #include /#inclu
16、de #define PIPESIZE 8#define PRODUCER 0#define CONSUMER 1#define RUN 0 /* statu of process */#define WAIT 1 /* statu of process */#define READY 2 /* statu of process */#define NORMAL 0#define SLEEP 1#define AWAKE 2#include /Process Control block struct pcb char *name; int statu; int time; ; /* times
17、 of execution */ /Buffer struct pipetype char type; /type int writeptr; /Write pointer int readptr; /Read pointer struct pcb *pointp; /* write wait point */ struct pcb *pointc; ; /* read wait point */ int pipePIPESIZE; /Buffer array struct pipetype pipetb; struct pcb process2; /number of producer -
18、number of consumer,buffer. count = 8:too many prodecers; number of times, ret-present status char in2; int runp(),runc(),prn(); pipetb.type = c; pipetb.writeptr = 0; pipetb.readptr = 0; pipetb.pointp = pipetb.pointc = NULL; processPRODUCER.name = Producer0; processCONSUMER.name = Consumer0; processP
19、RODUCER.statu = processCONSUMER.statu = READY; processPRODUCER.time = processCONSUMER.time = 0; output = 0;printf(Now starting the program!n); printf( Press p1 to run PRODUCER1, press p2 to run PRODUCER2.n press c to run CONSUMER.n); /PRODUCER1-product 1 new data, PRODUCER2-product 2 new data printf
20、( Press e to exit from the program.n); for(i=0;i1000;i+)in0=N; while(in0=N)scanf(%s,in); if(in0!=e&in0!=p&in0!=c) /when not p,c,e continuein0=N; if(in0=p&processPRODUCER.statu=READY) /producer and ready if(in1 = 2) /producer2 int m; for(m=0;m 3) /the number of waitting producer over 4,waitqueue=4 pr
21、intf(wrong!n); continue; if(countstatu=READY; runc(process,pipe,&pipetb,CONSUMER); countr-; printf(countr=%dn,countr); if(countr=0) pipetb.pointc=NULL; else if(in1 = 1) /producer1 if(countp 3) printf(wrong!n); continue; if(countstatu=READY; runc(process,pipe,&pipetb,CONSUMER); countr-; printf(countr
22、=%dn,countr); if(countr=0)pipetb.pointc=NULL; if(in0=c&processCONSUMER.statu=READY) /consumer and readyif(ret=runc(process,pipe,&pipetb,CONSUMER)=SLEEP) /sleeppipetb.pointc = &processCONSUMER; if(ret=AWAKE) /awake(pipetb.pointp)-statu=READY;output=(output+1)%100; runp(output,process,pipe,&pipetb,PRO
23、DUCER);countp-;printf(countp=%dn,countp);if(countp=0)pipetb.pointp=NULL;if(in0=p&processPRODUCER.statu=WAIT) /producer and wait if(in1 = 2) /producer2 int m; for(m=0;m 3) printf(wrong!n); printf(PRODUCER is waiting, cant be scheduled.n); continue; countp+; printf(countp=%dn,countp); else if(in1 = 1)
24、 /producer1 if(countp 3) printf(wrong!n); printf(PRODUCER is waiting, cant be scheduled.n); continue; countp+; printf(countp=%dn,countp); printf(Look out.n);/printf(PRODUCER is waiting, cant be scheduled.n); if(in0=c&processCONSUMER.statu=WAIT) /consumer and wait if(countr 3) printf(wrong!n); printf
25、(CONSUMER is waiting, cant be scheduled.n); continue; countr+;printf(countr=%dn,countr);printf(Look out!n); /printf(CONSUMER is waiting, cant be scheduled.n); if(in0=e) exit(1); prn(process,pipe,pipetb); in0=N; runp(out,p,pipe,tb,t) /* run producer */ int out,pipe,t; struct pcb p; struct pipetype *t
26、b; pt.statu=RUN; printf(run PRODUCER. product %d ,out); if(count=8) /buffer over 8 pt.statu=WAIT; return(SLEEP); tb-writeptr=tb-writeptr%8; /only has pipetb-writeptr=out; /change tb-writeptr+; printf(writeptr%dn,tb-writeptr); count+; printf(count=%dn,count); pt.time+; /printf(time+%dn,pt.time); pt.s
27、tatu=READY; if(tb-pointc)!=NULL) /printf(返回AWAKE); return(AWAKE); return(NORMAL); runc(p,pipe,tb,t) /* run consumer */ int pipe,t; struct pcb p; struct pipetype *tb; int c; pt.statu = RUN; printf(run CONSUMER. ); if(countreadptr; pipetb-readptr=0; tb-readptr+; tb-readptr=tb-readptr%8; printf(readptr
28、=%dn,tb-readptr); printf( use %d ,c); count-; printf(count=%dn,count); pt.time+; /printf(time+%dn,pt.time); pt.statu=READY; if(tb-pointp!=NULL) /printf(返回AWAKEn); return(AWAKE); return(NORMAL); prn(p,pipe,tb) int pipe; struct pipetype tb; struct pcb p; int i; printf(n ); for(i=0;iPIPESIZE;i+) printf
29、(- ); printf(n |);for(i=0;iPIPESIZE;i+) /pipe insideif(pipei!=0) /pipei has somethingprintf( %2d |,pipei);elseprintf( |); printf(n ); for(i=0;i=1) /number of producer =1 printf(%d PRODUCER wait ,countp); else printf(PRODUCER ready ); if(pCONSUMER.statu=WAIT)|countr=1) printf(%d CONSUMER wait ,countr
30、); else printf(CONSUMER ready ); printf(n); printf(n#n); 拓展點(diǎn):設(shè)置了等待隊(duì)列的長(zhǎng)度,并顯示等待隊(duì)列內(nèi)部情況四、 實(shí)驗(yàn)結(jié)果(截圖)生產(chǎn)者:情況一 正常生產(chǎn)情況二 超過緩沖區(qū)情況三 超過等待隊(duì)列消費(fèi)者:情況一 正常情況二 無(wú)產(chǎn)品可消費(fèi)又開始生產(chǎn):實(shí)驗(yàn)四 進(jìn)程的管道通信一、 實(shí)驗(yàn)?zāi)康募由顚?duì)進(jìn)程概念的理解,明確進(jìn)程和程序的區(qū)別;學(xué)習(xí)進(jìn)程創(chuàng)建的過程,進(jìn)一步認(rèn)識(shí)并發(fā)執(zhí)行的實(shí)質(zhì);分析進(jìn)程爭(zhēng)用資源的現(xiàn)象,學(xué)習(xí)解決進(jìn)程互斥的方法;學(xué)習(xí)解決進(jìn)程同步的方法;掌握Linux系統(tǒng)進(jìn)程間通過管道通信的具體實(shí)現(xiàn)方法。二、 實(shí)驗(yàn)原理1.基本概念:進(jìn)程的概念;進(jìn)程與程
31、序的區(qū)別;并發(fā)執(zhí)行的概念進(jìn)程互斥的概念;進(jìn)程通信的基本原理2.系統(tǒng)調(diào)用:設(shè)置系統(tǒng)調(diào)用號(hào):設(shè)置多條系統(tǒng)調(diào)用命令,并賦予每條系統(tǒng)調(diào)用命令一個(gè)唯一的系統(tǒng)調(diào)用號(hào)處理系統(tǒng)調(diào)用:OS中有一張系統(tǒng)調(diào)用入口表,表中每個(gè)表目對(duì)應(yīng)一條系統(tǒng)調(diào)用命令,包含該系統(tǒng)調(diào)用自帶參數(shù)的數(shù)目、系統(tǒng)調(diào)用命令處理程序的入口地址等。OS內(nèi)核便是根據(jù)所輸入的系統(tǒng)調(diào)用號(hào)在該表中查找到相應(yīng)的系統(tǒng)調(diào)用,進(jìn)而轉(zhuǎn)入它的入口地址去執(zhí)行系統(tǒng)調(diào)用程序。Linux的系統(tǒng)調(diào)用機(jī)制:通過中斷機(jī)制實(shí)現(xiàn)三、 實(shí)驗(yàn)內(nèi)容(源碼、注釋、基礎(chǔ)內(nèi)容、擴(kuò)展點(diǎn)等)#include #include #include #include #include int main() i
32、nt pid1,pid2,pid3; int fd2; char outpipe50,inpipe50; pipe(fd); while (pid1=fork() = -1); if(pid1 = 0) printf(s1n); lockf(fd1,1,0);/ printf(s11n); sprintf(outpipe,I am the 1st!); write(fd1,outpipe,50); sleep(3); lockf(fd1,0,0); /sleep(2); exit(0); else while(pid2=fork() = -1); if(pid2 = 0) printf(s2n
33、);/ if(pid1 != 0)/ wait(0);/ printf(s22n); lockf(fd1,1,0); /printf(f1); sprintf(outpipe,I am the 2nd!); write(fd1,outpipe,50); sleep(2); lockf(fd1,0,0); /sleep(2); exit(0); else while(pid3=fork() = -1); if (pid3 = 0) printf(s3n); lockf(fd1,1,0); sprintf(outpipe,I am the 3rd!); write(fd1,outpipe,50); sleep(2); lockf(fd1,0,0); exit(0); else wait(0); read(fd0,inpipe,50); printf(%s n,inpipe);/ printf(f1); wait(0); read(fd0,inpipe,50);/ printf(f2); printf(%s n,inpipe); wait(0); read(fd0,inpipe,50); printf(%s n,inpipe); exit(0); r
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度旅游發(fā)展規(guī)劃與咨詢服務(wù)合同3篇
- 2025年度聯(lián)合開設(shè)小貸公司經(jīng)營(yíng)合同6篇
- 2024年音樂節(jié)場(chǎng)地布置租賃合同
- 2024建筑施工總包合同
- 2024配件采購(gòu)與技術(shù)支持服務(wù)合同范本3篇
- 2024年項(xiàng)目外包合同:軟件開發(fā)項(xiàng)目的外包與實(shí)施
- 2024物業(yè)管理公司監(jiān)控設(shè)備采購(gòu)合同
- 2024年網(wǎng)絡(luò)安全培訓(xùn)與咨詢服務(wù)合同
- 2024版挖掘機(jī)租賃合同范本3篇
- 二零二五年度教育培訓(xùn)機(jī)構(gòu)加盟合同(含品牌授權(quán)及運(yùn)營(yíng)指導(dǎo))3篇
- 常用靜脈藥物溶媒的選擇
- 當(dāng)代西方文學(xué)理論知到智慧樹章節(jié)測(cè)試課后答案2024年秋武漢科技大學(xué)
- 2024年中國(guó)心力衰竭診斷和治療指南2024版
- HCCDP 云遷移認(rèn)證理論題庫(kù)
- 臺(tái)大公開課--《紅樓夢(mèng)》筆記剖析
- 工傷保險(xiǎn)待遇及案例分析PPT課件
- 底總結(jié)報(bào)告2017年初開場(chǎng)計(jì)劃策劃模版圖文可隨意編輯修改課件
- 詢問調(diào)查筆錄內(nèi)容來(lái)自dedecms - 稅務(wù)局(稽查局)
- 石油化工中心化驗(yàn)室設(shè)計(jì)規(guī)范
- 自己總結(jié)的清華斯維爾節(jié)能問題解答(共21頁(yè))
- 烹飪專業(yè)課程及課表設(shè)置
評(píng)論
0/150
提交評(píng)論