時間片輪轉演算法實現

2021-08-20 20:24:39 字數 1598 閱讀 8152

#include

#include

#define null 0

typedef struct quen /*定義結構*/

char pname[8];

int time1;

int time2;

char state;

struct quen *next;

}quen;

main()/*主程式*/

quen *q,*p,*head,*m;

char str[8],f;

int t,d,n;

system("clear");

printf("enter the maxnumber of nodes(n):\n");/*輸入程序數*/

scanf("%d",&n);

d=n;

if(d>0)

printf("enter thepname:");

scanf("%s",str);

printf("enter the need time:");

scanf("%d",&t);

head=p=(quen *)malloc(sizeof(quen));

strcpy(p->pname,str);

p->time1=t;

p->time2=0;

p->state='r';

p->next=null;

head=p;

getchar();

--d;}

while(d>0)

printf("process name need time runned static\n");

dowhile(q!=head);

printf("\n");

dowhile(q!=head);

printf("\n");

head=head->next;

q=head;

p->next=head;

elsewhile(q!=head);

printf("\n");

head=head->next;

q=head;

p=p->next;}

printf("is it needing new process?(y or n)\n");/*是否加入新的程序*/

getchar();

scanf("%c",&f);

if(f=='y'||f=='y')

else}

}}while(q->next->state!='e');

printf("the processes are finished\n");

實驗結果:

程式說明:在輪轉演算法中,系統根據fcfs策略,將所有的就緒程序排成乙個就緒佇列,並可設定每隔一定時間間隔(如30ms)即產生一次中斷,啟用系統中的程序排程程式,完成一次排程,將cpu分配給隊首程序,令其執行。當該程序的時間片耗盡或執行完畢時,系統再次將cpu分配給新的隊首程序(或新到達的緊迫程序)。由此,可以保證就緒佇列中的所有程序在乙個確定的時間段內,都能夠獲得一次cpu執行。

時間片輪轉演算法實現

程式設計實現時間片輪轉演算法,並求出每個作業的完成時間 周轉時間 帶權周轉時間,及平均周轉時間 平均帶權周轉時間。任選一種高階語言實現 選擇1 2種排程演算法 能夠輸入程序的基本資訊,如程序名 提交時間 預估執行時間等 根據選擇的排程演算法顯示程序排程順序 顯示完成排程後每個程序的開始時間 完成時間...

時間片輪轉演算法

include include include include include include includeusing namespace std 初始化程序池 初始化就緒佇列 rr演算法 struct pcb pcb string name,int atime,int rtime,char st...

時間片輪轉

時間片輪轉排程演算法,這種演算法是將程序控制塊按照進入就緒佇列的先後次序排成佇列。關於就緒佇列的操作就是從隊頭摘下乙個程序控制塊和從隊尾掛入乙個程序控制塊。單處理器系統中程序控制塊分成乙個正在執行程序的程序控制塊 就緒程序的程序控制塊組織成的就緒佇列和等待程序的程序控制塊組成的等待佇列。由於實驗模擬...