




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、#include<stdio.h>#include<stdlib.h>#include <conio.h>#include<math.h>#define N 20#define MAX 100typedef struct PCB /pcb進程控制塊定義 int numN; /進程序號 char name10; /進程名 char state; /進程狀態(tài) int tijiaotime; /進程到達時間 int runtime; /進程開始時間 int finishtime; /進程結束時間 int needtime; /服務時間 int pro;
2、/進程優(yōu)先級 struct PCB *next; /鏈接指針 指向下個作業(yè)的pcb;struct PCB *head_input;struct PCB *head_run;struct PCB *head_run_pre;unsigned long current; /記錄系統(tǒng)當前時間的變量int time=10000,n; /計時器 pcb *head=NULL,*p,*q;void getInfo() /創(chuàng)建進程 int num; printf("n請輸入要建立的進程個數(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進程號 進程名 到達時間 服務時間 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.先來先服務調度算法*void run_fcfo(pcb *p1)/定義先來先到服務的算法 time = p1->tijiaotime > time? p1->tijiaotime:time; p1->runtime=time; printf("n現(xiàn)在時間是%d,開始運行進程%sn",time,p1->name); time+=p1->needtime; p1->state='F
5、39; p1->finishtime=time; printf("進程名 開始時間 所需時間 結束時間n"); printf("%s %d %d %d ",p1->name,p1->runtime,p1->needtime,p1->finishtime);void fcfo()/定義運行進程函數(shù) int i,j,t; for(j=0;j<n;j+) p=head; t=10000; for(i=0;i<n;i+) /找到當前未完成的進程 if(p->tijiaotime<t && p-
6、>state='W') t=p->tijiaotime; q=p; /標記當前未完成的進程 p=p->next; run_fcfo(q); / *2.優(yōu)先級調度服務算法*int readydata() /建立就緒隊列 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() /運行進程函數(shù) head_run->runtime-=10; head_run->pro+; struct PCB *p1,*p2; printf("時間片的大小 %d",current); current+=10; printf(" %s 開始n",hea
8、d_run->name); printf("時間片的大小 %d",current); printf(" %s 結束n",head_run->name); if(head_run->runtime<=0) /判斷進程是否運行結束 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("請重新輸入要建立的進程個數(shù):"); scanf("%d",&numpro); printf("請依次輸入 進程名 運行時間 優(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.時間片輪轉調度服務算法*void shijianpian()int b,i,X,t,k;int aMAX;/存放進程的剩余時間int cntMAX;/存放進程調度次數(shù)printf("請輸入進程數(shù):&q
11、uot;);scanf("%d",&X);printf("n請輸入時間片t大小:");scanf("%d",&t);printf("n請依次輸入各個進程的服務時間");for(i=0;i<X;i+)scanf("%d",&ai);cnti=0;printf("被調度進程t進程調度次數(shù) t本次運行時間結果t剩余時間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. 按先來先到服務調度的算法模擬n"); printf(" *"); getInfo(); fcfo(); printf("n *"); printf("n 2. 按優(yōu)先級調
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 寧夏回族自治區(qū)銀川市興慶區(qū)高級中學2025屆高考化學試題考前最后一卷預測卷(一)含解析
- 云南省文山壯族苗族自治州富寧縣2025年三年級數(shù)學第二學期期末達標檢測試題含解析
- 上海市楊浦區(qū)名校2025年中考化學試題模擬試卷解析含解析
- 山東泰安2024-2025學年初三下學期考試物理試題理試題分類匯編含解析
- 浙江舟山群島新區(qū)旅游與健康職業(yè)學院《食品感官分析》2023-2024學年第一學期期末試卷
- 盆底康復治療規(guī)范與方法
- 湛江市大成中學高一下學期第一次月考物理試題
- 康復護理頸椎病課件
- 2025海運合同樣本范文
- 2025版企業(yè)辦公租賃合同范本
- 2025年第三屆天揚杯建筑業(yè)財稅知識競賽題庫附答案(501-1000題)
- 黃岡市2025年春季九年級調研考試語文試卷
- 國開電大軟件工程形考作業(yè)3參考答案 (一)
- 育兒真經知到課后答案智慧樹章節(jié)測試答案2025年春浙江中醫(yī)藥大學
- 2025合同模板個人車位轉讓合同 范本
- 2025-2030動力電池回收產業(yè)市場深度調研及發(fā)展趨勢與投資戰(zhàn)略研究報告
- 2025《中國建設銀行房產抵押合同》
- 企業(yè)集團文件與檔案管理制度
- 2024福建漳州市九龍江集團有限公司招聘10人筆試參考題庫附帶答案詳解
- 建筑行業(yè)勞動保護制度與措施
- 中國少數(shù)民族文化知到課后答案智慧樹章節(jié)測試答案2025年春云南大學
評論
0/150
提交評論