![操作系統(tǒng)實(shí)驗(yàn)處理機(jī)調(diào)C語言實(shí)現(xiàn)_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/5/a1b78c14-d327-434f-b574-bf876fc0f396/a1b78c14-d327-434f-b574-bf876fc0f3961.gif)
![操作系統(tǒng)實(shí)驗(yàn)處理機(jī)調(diào)C語言實(shí)現(xiàn)_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/5/a1b78c14-d327-434f-b574-bf876fc0f396/a1b78c14-d327-434f-b574-bf876fc0f3962.gif)
![操作系統(tǒng)實(shí)驗(yàn)處理機(jī)調(diào)C語言實(shí)現(xiàn)_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/5/a1b78c14-d327-434f-b574-bf876fc0f396/a1b78c14-d327-434f-b574-bf876fc0f3963.gif)
![操作系統(tǒng)實(shí)驗(yàn)處理機(jī)調(diào)C語言實(shí)現(xiàn)_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/5/a1b78c14-d327-434f-b574-bf876fc0f396/a1b78c14-d327-434f-b574-bf876fc0f3964.gif)
![操作系統(tǒng)實(shí)驗(yàn)處理機(jī)調(diào)C語言實(shí)現(xiàn)_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/5/a1b78c14-d327-434f-b574-bf876fc0f396/a1b78c14-d327-434f-b574-bf876fc0f3965.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、#include<stdio.h>#include<stdlib.h>#include <conio.h>#include<math.h>#define N 20#define MAX 100typedef struct PCB /pcb進(jìn)程控制塊定義 int numN; /進(jìn)程序號(hào) char name10; /進(jìn)程名 char state; /進(jìn)程狀態(tài) int tijiaotime; /進(jìn)程到達(dá)時(shí)間 int runtime; /進(jìn)程開始時(shí)間 int finishtime; /進(jìn)程結(jié)束時(shí)間 int needtime; /服務(wù)時(shí)間 int pro;
2、/進(jìn)程優(yōu)先級 struct PCB *next; /鏈接指針 指向下個(gè)作業(yè)的pcb;struct PCB *head_input;struct PCB *head_run;struct PCB *head_run_pre;unsigned long current; /記錄系統(tǒng)當(dāng)前時(shí)間的變量int time=10000,n; /計(jì)時(shí)器 pcb *head=NULL,*p,*q;void getInfo() /創(chuàng)建進(jìn)程 int num; printf("n請輸入要建立的進(jìn)程個(gè)數(shù):"); scanf("%d",&n); for(num=0;num&l
3、t;n;num+) p=(pcb *)malloc(sizeof(pcb); if(head=NULL) head=p;q=p; printf("依次輸入:n進(jìn)程號(hào) 進(jìn)程名 到達(dá)時(shí)間 服務(wù)時(shí)間 n"); scanf("%st%st%dt%d",&p->num,&p->name,&p->tijiaotime,&p->needtime); if(p->tijiaotime < time) time=p->tijiaotime; q->next=p; p->runtime=0
4、; p->finishtime=0; p->next=NULL; p->state='W' q=p; / *1.先來先服務(wù)調(diào)度算法*void run_fcfo(pcb *p1)/定義先來先到服務(wù)的算法 time = p1->tijiaotime > time? p1->tijiaotime:time; p1->runtime=time; printf("n現(xiàn)在時(shí)間是%d,開始運(yùn)行進(jìn)程%sn",time,p1->name); time+=p1->needtime; p1->state='F
5、39; p1->finishtime=time; printf("進(jìn)程名 開始時(shí)間 所需時(shí)間 結(jié)束時(shí)間n"); printf("%s %d %d %d ",p1->name,p1->runtime,p1->needtime,p1->finishtime);void fcfo()/定義運(yùn)行進(jìn)程函數(shù) int i,j,t; for(j=0;j<n;j+) p=head; t=10000; for(i=0;i<n;i+) /找到當(dāng)前未完成的進(jìn)程 if(p->tijiaotime<t && p-
6、>state='W') t=p->tijiaotime; q=p; /標(biāo)記當(dāng)前未完成的進(jìn)程 p=p->next; run_fcfo(q); / *2.優(yōu)先級調(diào)度服務(wù)算法*int readydata() /建立就緒隊(duì)列 if(head_input->next=NULL) return 0; struct PCB *p1=head_input->next,*pmax,*p2; int maxpro=0xffff; pmax=p1; p2=head_input; while(p1!=NULL) if(p1->pro<maxpro) maxpr
7、o=p1->pro; head_run_pre=p2;pmax=p1; p2=p1; p1=p1->next; head_run=pmax; head_run_pre->next=head_run->next; return 1;void runprocess() /運(yùn)行進(jìn)程函數(shù) head_run->runtime-=10; head_run->pro+; struct PCB *p1,*p2; printf("時(shí)間片的大小 %d",current); current+=10; printf(" %s 開始n",hea
8、d_run->name); printf("時(shí)間片的大小 %d",current); printf(" %s 結(jié)束n",head_run->name); if(head_run->runtime<=0) /判斷進(jìn)程是否運(yùn)行結(jié)束 else p1=head_input; p2=head_input->next; p1->next=head_run; head_run->next=p2; int readyprocess() while(1) if(readydata()=0) return 0; else runpr
9、ocess(); void Init() head_input=new PCB; head_input->next=NULL; current=0; int numpro; printf("請重新輸入要建立的進(jìn)程個(gè)數(shù):"); scanf("%d",&numpro); printf("請依次輸入 進(jìn)程名 運(yùn)行時(shí)間 優(yōu)先級n"); for(int i=0;i<numpro;i+) struct PCB *p1=new PCB; scanf("%s",p1->name); scanf("
10、;%d",&p1->runtime); scanf("%d",&p1->pro); p1->state='C' p1->next=NULL; struct PCB *p2=head_input->next; head_input->next=p1; p1->next=p2; / *3.時(shí)間片輪轉(zhuǎn)調(diào)度服務(wù)算法*void shijianpian()int b,i,X,t,k;int aMAX;/存放進(jìn)程的剩余時(shí)間int cntMAX;/存放進(jìn)程調(diào)度次數(shù)printf("請輸入進(jìn)程數(shù):&q
11、uot;);scanf("%d",&X);printf("n請輸入時(shí)間片t大小:");scanf("%d",&t);printf("n請依次輸入各個(gè)進(jìn)程的服務(wù)時(shí)間");for(i=0;i<X;i+)scanf("%d",&ai);cnti=0;printf("被調(diào)度進(jìn)程t進(jìn)程調(diào)度次數(shù) t本次運(yùn)行時(shí)間結(jié)果t剩余時(shí)間n");k=1;while(k)for(i=0;i<X;i+)if(ai!=0)if(ai>=t) ai-=t; b+=t;
12、 cnti=cnti+1; printf("nt%dtt%dtt%dtt%d",i+1,cnti,b,ai); else b=b+ai; cnti=cnti+1; ai=0; printf("nt%dtt%dtt%dtt%d",i+1,cnti,b,ai);else continue;for(i=0;i<X;i+)if(ai!=0) k=1;break;else continue;if(i>=X) k=0;void main() printf(" *"); printf("n 1. 按先來先到服務(wù)調(diào)度的算法模擬n"); printf(" *"); getInfo(); fcfo(); printf("n *"); printf("n 2. 按優(yōu)先級調(diào)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度辦公室翻新與餐飲店改造設(shè)計(jì)施工合同
- 二零二五年度城市公共安全報(bào)警系統(tǒng)電路升級改造合同
- 提取公積金借款合同
- 銷售抵押合同
- 電商零售平臺(tái)開發(fā)合同
- 個(gè)人理財(cái)指南
- 農(nóng)產(chǎn)品公共檢測與溯源體系建設(shè)作業(yè)指導(dǎo)書
- 質(zhì)量管理工具與方法應(yīng)用作業(yè)指導(dǎo)書
- 平面設(shè)計(jì)聘用合同
- 2025年廣西貨運(yùn)考試題目
- 【鋼鐵冶煉】-銻冶煉先關(guān)工藝
- 護(hù)理管理組織體系架構(gòu)圖
- 漸變方格模板
- 環(huán)境因素匯總識(shí)別及評價(jià)表(保衛(wèi)部 )
- GB/T 33880-2017熱等靜壓鋁硅合金板材
- 消防安全風(fēng)險(xiǎn)辨識(shí)清單
- 2023年版勞動(dòng)實(shí)踐河北科學(xué)技術(shù)出版社一年級下冊全冊教案
- 方案報(bào)審表(樣表)
- 除銹、油漆檢驗(yàn)批質(zhì)量驗(yàn)收記錄樣表
- pp顧問的常見面試問題
- 法理學(xué)原理與案例完整版教學(xué)課件全套ppt教程
評論
0/150
提交評論