導航:首頁 > 源碼編譯 > 操作系統調度演算法代碼

操作系統調度演算法代碼

發布時間:2022-07-05 19:51:22

1. 操作系統模擬電梯調度演算法C語言程序

這是數學建模的題目,太難了。
只能給點提示,希望有用。一,用到隨機函數。二,調度演算法為FIFO和電梯調度。參考操作系統。三,文件io用到#include
<fstream>頭文件

2. 操作系統-cpu調度演算法設計

對等動態優先權演算法,進程調度過程掌握情況;考查學生的寫演算法和編程能力等;考查學生的分析問題和解決問題的能力;實驗報告的撰寫能力等。 設計思路: (1)先對就緒隊列,阻塞隊列,cpu的進行初始化。 (2)進行進程調度的選擇。 1)cpu,就緒...

3. 實時操作系統常用任務調度演算法有哪些

實時操作系統常用任務調度演算法有哪些
操作系統常用的批處理作業調度演算法
1.先來先服務調度演算法
先來先服務(FCFS)調度演算法是一種最簡單的調度演算法,該演算法既可用於作業調度,也可用於進程調度。當在作業調度中採用該演算法時,每次調度都是從後備作業隊列中選擇一個或多個最先進入該隊列的作業,將它們調入內存,為它們分配資源、創建進程,然後放入就緒隊列。在進程調度中採用FCFS演算法時,則每次調度是從就緒隊列中選擇一個最先進入該隊列的進程,為之分配處理機,使之投入運行。該進程一直運行到完成或發生某事件而阻塞後才放棄處理機。
2.短作業(進程)優先調度演算法

4. 操作系統優先順序調度演算法怎麼樣用c的實現謝謝了,大神幫忙啊

進程調度源程序如下: jingchendiao.cpp #include "stdio.h" #include <stdlib.h> #include <conio.h> #define getpch(type) (type*)malloc(sizeof(type)) #define NULL 0 struct pcb { /* 定義進程式控制制塊PCB */ char name[10]; char state; int super; int ntime; int rtime; struct pcb* link; }*ready=NULL,*p; typedef struct pcb PCB; sort() /* 建立對進程進行優先順序排列函數*/ { PCB *first, *second; int insert=0; if((ready==NULL)||((p->super)>(ready->super))) /*優先順序最大者,插入隊首*/ { p->link=ready; ready=p; } else /* 進程比較優先順序,插入適當的位置中*/ { first=ready; second=first->link; while(second!=NULL) { if((p->super)>(second->super)) /*若插入進程比當前進程優先數大,*/ { /*插入到當前進程前面*/ p->link=second; first->link=p; second=NULL; insert=1; } else /* 插入進程優先數最低,則插入到隊尾*/ { first=first->link; second=second->link; } } if(insert==0) first->link=p; } } input() /* 建立進程式控制制塊函數*/ { int i,num; clrscr(); /*清屏*/ printf("\n 請輸入進程號?"); scanf("%d",&num); for(i=0;i<num;i++) { printf("\n 進程號No.%d:\n",i); p=getpch(PCB); printf("\n 輸入進程名:"); scanf("%s",p->name); printf("\n 輸入進程優先數:"); scanf("%d",&p->super); printf("\n 輸入進程運行時間:"); scanf("%d",&p->ntime); printf("\n"); p->rtime=0;p->state='w'; p->link=NULL; sort(); /* 調用sort函數*/ } } int space() { int l=0; PCB* pr=ready; while(pr!=NULL) { l++; pr=pr->link; } return(l); } disp(PCB * pr) /*建立進程顯示函數,用於顯示當前進程*/ { printf("\n qname \t state \t super \t ndtime \t runtime \n"); printf("|%s\t",pr->name); printf("|%c\t",pr->state); printf("|%d\t",pr->super); printf("|%d\t",pr->ntime); printf("|%d\t",pr->rtime); printf("\n"); } check() /* 建立進程查看函數 */ { PCB* pr; printf("\n **** 當前正在運行的進程是:%s",p->name); /*顯示當前運行進程*/ disp(p); pr=ready; printf("\n ****當前就緒隊列狀態為:\n"); /*顯示就緒隊列狀態*/ while(pr!=NULL) { disp(pr); pr=pr->link; }

5. (操作系統)編寫進程調度演算法程序

#include<iostream>
#include<string>
#include<iomanip>
#include<windows.h>
using namespace std;
typedef struct Process
{ string id;
int arrive_time;
int sever_time;
int finish_time;
int turnover_time;
Process * next;
}Process,* Linkp; class FCFS_schele
{ public: FCFS_schele()
{
Creat_queue();
}
~FCFS_schele();
void Creat_queue();
void Insert_queue();
void orderInsert_queue();
void Out_queue();
void Printall();
void Sort_queue();
Process Gethead();
private:
Linkp head,tail;
int num;
Process Creat_process();
};///////////////////////////////////////////////////////方法的具體實現void FCFS_schele::Creat_queue()
{ head=new Process;
head->next=0;
tail=head;
num=0;
}
ostream& operator <<(ostream& out,Process& a) //對插入流運算符<<進行重載
{ out<<"process id:"<<a.id <<" arrivetime:"<<a.arrive_time
<<" severtime:"<<a.sever_time<<endl;
return(out);
}Process FCFS_schele::Creat_process()
{ Process a;

cout<<"please input process id"<<num+1<<":";
cin>>a.id ;
cout<<"please input process arrivetime:";
cin>>a.arrive_time ;
cout<<"please input process severtime:";
cin>>a.sever_time ;
a.finish_time=0;
a.turnover_time=0;
a.next =0;
return(a);
} void FCFS_schele::Insert_queue ()
{ Linkp p;
p=new Process;
*p=Creat_process();
if(num==0)
{p->finish_time=p->arrive_time+p->sever_time;<br> p->turnover_time=p->finish_time-p->arrive_time ;<br> }
else
{p->finish_time=tail->finish_time + p->sever_time ;<br> p->turnover_time=p->finish_time - p->arrive_time ;<br> }
tail->next=p;
tail=p;
num++;
}
void FCFS_schele::Out_queue() //進程調度出隊
{ Linkp p;
p=head->next;
if(!p) cout<<"empty!\n";
else
{ head->next=p->next;
if(p->next==NULL) tail=head;
cout<<"process id:"<<p->id<<" arrivetime:"<<p->arrive_time
<<" severtime:"<<p->sever_time<<" finishtime:"<<p->finish_time
<<" turnovertime:"<<p->turnover_time <<endl;
delete p;
num--;
}
}
Process FCFS_schele::Gethead()throw(int)

{ Linkp p;
p=head->next;
if(p) return(*p);
else throw 1; //當隊空無法返回Process類型返回值時拋出異常錯誤整形值1

}
void FCFS_schele::Printall()
//列印進程隊列所有進程信息
{ Linkp p;
float sum_wghtime=0;
p=head->next;
cout<<" Process Information\n";
cout<<"process id arrivetime severtime finishtime turnovertime weightime\n";
while(p)
{ cout<<p->id<<setw(14)<<p->arrive_time
<<setw(14)<<p->sever_time<<setw(14)<<p->finish_time<<setw(14)<<p->turnover_time
<<setw(14)<<float(p->turnover_time)/float(p->sever_time )<<endl;
sum_wghtime=sum_wghtime+(float)p->turnover_time/p->sever_time;
p=p->next;
}
cout<<"平均帶權周轉時間為:"<<sum_wghtime/num<<endl;
}
void FCFS_schele::Sort_queue ()
//採用選擇法將隊列中的進程按servertime長短進行換值不換址的排序{ Linkp location,search,record,track;
Process temp;
track=head->next;
location=track->next ;
while(location && location->next )
{ record=search=location;

while(search)
{ if(search->sever_time <record->sever_time ) record=search;
search=search->next ;
} if(record!=location)
{
temp=*record;
record->arrive_time =location->arrive_time ;
record->id =location->id ;
record->sever_time =location->sever_time ;

location->id =temp.id;
location->sever_time =temp.sever_time ;
location->arrive_time =temp.arrive_time ;
location->finish_time =track->finish_time + location->sever_time ;
location->turnover_time =location->finish_time - location->arrive_time ;
}
track=location;
location=location->next ;
}
if(tail==location)
{tail->finish_time = track->finish_time +tail->sever_time ;<br> tail->turnover_time =tail->finish_time -tail->arrive_time ;<br> }}
FCFS_schele::~FCFS_schele ()
{ Linkp p;
while(p=head)
{
head=head->next ;
delete p;
}
cout<<"the storage of memory has been distory!\n";
} void FCFS_schele::orderInsert_queue () //進程插入排序
{ Linkp p,pr;
p=new Process;
*p=Creat_process(); if(num==0)
{
head->next=p;
tail=p;
p->finish_time =p->arrive_time + p->sever_time ;
p->turnover_time =p->finish_time - p->arrive_time ;
}
else
{
pr=head->next ;
while(pr->next && p->sever_time >= pr->next->sever_time )
pr=pr->next;
if(pr->next==0)
{
p->finish_time = tail->finish_time + p->sever_time ;
p->turnover_time =p->finish_time - p->arrive_time ;
tail->next=p;
tail=p;
}
else
{
p->next =pr->next ;
pr->next=p;
while(p)
{
p->finish_time =pr->finish_time + p->sever_time ;
p->turnover_time = p->finish_time - p->arrive_time ;
pr=p;
p=p->next ;
}
}

}
num++;
} void main()
{
// DWORD start=GetTickCount();

FCFS_schele os;
os.orderInsert_queue ();
os.orderInsert_queue ();
os.orderInsert_queue ();
os.orderInsert_queue ();
os.orderInsert_queue ();
// os.orderInsert_queue ();
// os.orderInsert_queue ();
os.Printall ();
// os.Sort_queue ();
os.Sort_queue ();
os.Printall ();
os.Out_queue ();
os.Out_queue ();
os.Out_queue ();
os.Out_queue ();
/* try{
cout<<os.Gethead () ;
}
catch(int i)
{ if(i==1) cout<<"empty!\n";
}*/
//
// DWORD end=GetTickCount();
// cout<<"spend time:"<<(end-start)<<endl;
/*

os.Out_queue ();
*/
}

6. 急求一個用C或C++寫的關於操作系統 調度問題的代碼(FCFS和SJF調度演算法)

你們這個是操作系統的作業吧。
記得我們上學的時候就是這個。

7. 操作系統的調度演算法

1)10:00Job1到達並投入運行。此時內存中有作業:Job1
2)10:05 Job2到達並進入內存。此時,Job1運行時間剩餘是25min, Job2運行剩餘時間是20min,根據SRTF,Job2開始運行。
3)10:25 Job2運行結束。Job3、Job4在後備隊列中,據SJF,Job3進入內存,據SRTF,Job3開始運行。內存:Job1、Job3
4)10:30 Job3運行結束。Job4在後備隊列中,Job4進入內存,據SRTF,Job4開始運行。內存:Job1、Job4
5)10:40 Job4運行結束。Job1重新繼續運行。
6)11:05 Job1運行結束。

8. 急求 程序代碼 c/c++ 操作系統中的 處理機調度演算法

#include <iostream>

#include <stdio.h>

#include <string>

//#include <windows.h>

using namespace std;

//hyugtyftydrtdtrdrrtrdrt

struct Node

{

string name;//進程(作業)名稱

int arriveTime;//到達時間

int ServerTime;//服務時間

int leftTime;//the left time

Node *link;//指向下一個節點的指針

};

class CProcess

{

public:

CProcess();//構造函數

~CProcess();//析構函數

const CProcess &operator =(const CProcess& p);//重載賦值操作符

void insertNode(string &na,int& at,int& st);//插入新元素(at由小到大)到鏈表合適的位置

void sort();//按照服務時間由大到小排序

bool isEmpty();//判斷是否為空

void destroy();//銷毀

int length();//求出鏈表長度

void print();//列印出元素

void FCFS();//先到先服務

void SJF();//短進程(作業)優先

void RR(int& q);//時間片輪轉

void priority();//優先權調度

protected:

Node *first;

Node *last;

};

const CProcess& CProcess::operator=(const CProcess& p)

{

Node *newNode;

Node *Current;

if(this!=&p)//避免自己給自己賦值

{

if(first!=NULL)//如果鏈表不為空

destroy();

if(p.first==NULL)

{//如果要拷貝的對象為空

this->first = NULL;

this->last = NULL;

}

else

{

Current = p.first;

first= new Node;

first->name=Current->name;//

first->arriveTime=Current->arriveTime;

first->ServerTime=Current->ServerTime;

first->link =NULL;

last =first;

Current = Current->link;

while(Current!=NULL)

{

newNode = new Node;

newNode->name=Current->name;

newNode->arriveTime=Current->arriveTime;

newNode->ServerTime=Current->ServerTime;

newNode->link=NULL;

last->link=newNode;

last=newNode;

Current = Current->link;

}

}

}

return *this;

}

CProcess::CProcess()

{//構造函數

first=NULL;

last=NULL;

}

CProcess::~CProcess()

{

Node *temp;

while(first!=NULL)

{

temp=first;

first=first->link;

delete temp;

}

last=NULL;

}

void CProcess::insertNode(string &na,int& at,int& st)

{//按照到達時間升序排序

Node *Current;

Node *trailCurrent;//指向Current的前一個節點

Node *newNode;

bool found;

newNode = new Node;//建立一個新節點

newNode->name=na;

newNode->arriveTime=at;

newNode->ServerTime=st;

newNode->link=NULL;//

if(first==NULL)//如果第一個節點為空(如果是第一次插入元素)

first=newNode;//將新節點賦給第一個節點

else

{//如果不是第一次

Current =first;

found = false;

while(Current!=NULL && !found)

{

if(Current->arriveTime >= at)

found = true;

else

{

trailCurrent = Current;

Current = Current->link;

}

}

if(Current==first)

{

newNode->link = first;

first = newNode;

}

else

{

trailCurrent->link = newNode;

newNode->link = Current;

}

}

}

int CProcess::length()

{

int count =0;//聲明變數,並初始化為0(用來記錄長度)

Node *Current;

Current = first;

while(Current!=NULL)//當前節點不為空,記錄值自加,一直向後遍歷,

{

count++;

Current = Current->link;

}

return count;//返回長度

}

void CProcess::sort()//按照服務時間,升序排列

{//冒泡排序

string sname;

int at;

int st;

Node *Current;//指向當前節點

Node *trailCurrent;//指向當前節點的前一個節點

for(trailCurrent=first->link;trailCurrent!=NULL;trailCurrent=trailCurrent->link)//控制條件有問題

{

for(Current=trailCurrent->link;Current!=NULL;Current=Current->link)//控制條件有問題

{

if(trailCurrent->ServerTime > Current->ServerTime)

{

sname=trailCurrent->name;

at=trailCurrent->arriveTime;

st=trailCurrent->ServerTime;

trailCurrent->name=Current->name;

trailCurrent->arriveTime=Current->arriveTime;

trailCurrent->ServerTime=Current->ServerTime;

Current->name=sname;

Current->arriveTime=at;

Current->ServerTime=st;

}

}

}

}

bool CProcess::isEmpty()//判斷是否為空

{

return (first==NULL);//如果第一個節點為空,返回值

}

void CProcess::print()

{

Node *Current;

Current = first->link;//頭節點賦給當前節點

while(Current!=NULL)//當前節點不為空,一直向後遍歷列印

{

cout<<Current->name<<" ";

cout<<Current->arriveTime<<" ";

cout<<Current->ServerTime<<"\n";

Current = Current->link;

}

}

void CProcess::destroy()

{

Node *temp;//定義一個臨時指針變數

while(first!=NULL)

{

temp=first;

first=first->link;

delete temp;

}

last=NULL;

}

void CProcess::FCFS()//先到先服務

{

Node *Current;

int T0=0;//完成時間

int T1=0;//周轉時間

Current = first->link;//頭節點賦給當前節點

while(Current!=NULL)

{

if(T0 < Current->arriveTime)

{

T0=Current->arriveTime+Current->ServerTime;

T1=T0-Current->arriveTime;

cout<<Current->name<<"\t";//列印出進程名

cout<<T0<<"\t";//列印出完成時間

cout<<T1<<"\n";//列印出周轉時間

Current = Current->link;

}

else

{

T0=Current->ServerTime+T0;

T1=T0-Current->arriveTime;//周轉時間等於,完成時間 - 到達時間

cout<<Current->name<<"\t";//列印出進程名

cout<<T0<<"\t";//列印出完成時間

cout<<T1<<"\n";//列印出周轉時間

Current = Current->link;

}

}

}

void CProcess::SJF()//短進程(作業)優先

{

//首先執行第一個到達的作業

Node *Current;

int T0=0;//完成時間

int T1=0;//周轉時間

T0=first->link->ServerTime+T0;

T1=T0-first->link->arriveTime;

cout<<first->link->name<<"\t";

cout<<T0<<"\t";//列印出完成時間

cout<<T1<<"\n";//列印出周轉時間

first->link=first->link->link;//刪除

//執行剩下的

sort();//對剩下的排序

Current = first->link;//頭節點賦給當前節點

while(Current!=NULL)

{

if(T0 < Current->arriveTime)

{

T0=Current->arriveTime+Current->ServerTime;

T1=T0-Current->arriveTime;

cout<<Current->name<<"\t";//列印出進程名

cout<<T0<<"\t";//列印出完成時間

cout<<T1<<"\n";//列印出周轉時間

Current = Current->link;

}

else

{

T0=Current->ServerTime+T0;

T1=T0-Current->arriveTime;//周轉時間等於,完成時間 - 到達時間

cout<<Current->name<<"\t";//列印出進程名

cout<<T0<<"\t";//列印出完成時間

cout<<T1<<"\n";//列印出周轉時間

Current = Current->link;

}

}

}

void CProcess::RR(int& q)//時間片輪轉

{

cout<<"時間片輪轉操作完成!\n";

}

void CProcess::priority()//優先權調度

{

cout<<"優先權操作完成!\n";

}

void main()

{

CProcess p0,p1,p2,p3,p4;

int at,st;

string na;

int judge=1;//控制退出程序

int choice;//控制選擇操作

while(judge)

{

cout<<"********************************************************\n";

cout<<"****** 說明:本程序適用於單道進程(作業) ******\n";

cout<<"******** 請選擇您的操作 ***************\n";

cout<<"*********輸入相應的數字,按下(Enter)鍵!**************\n";

cout<<"************* 5.錄入信息 ************\n";

cout<<"************* 1.先到先服務 ************\n";

cout<<"************* 2.短進程(作業)優先 ************\n";

cout<<"************* 3.時間片輪轉 ************\n";

cout<<"************* 4.優先權(靜態)調度 ************\n";

cout<<"************* 0.退出程序 ************\n";

cout<<"********************************************************\n";

cin>>choice;

switch(choice)

{

case 0:

judge=0;

break;

case 5:

cout<<"請輸入信息以「end」結束輸入!\n";

cout<<"進程名 到達時間 服務時間"<<endl;

while(na.compare("end"))//如果相等則會返回0

{

p0.insertNode(na,at,st);

cin>>na>>at>>st;

}

cout<<"錄入成功,目前的信息為:\n";

cout<<"進程名 到達時間 服務時間"<<endl;

p0.print();

break;

case 1://先到先服務

p1=p0;//拷貝一份

if(p1.isEmpty())

{

cout<<"請先錄入信息\n";

break;

}

else

{

cout<<"先到先服務\n";

cout<<"進程名 完成時間 周轉時間\n";

p1.FCFS();

break;

}

case 2://短作業優先

p2=p0;//拷貝一份

//p2.sort();

//p2.print();

if(p2.isEmpty())

{

cout<<"請先錄入信息\n";

break;

}

else

{

cout<<"短作業優先\n";

cout<<"進程名 完成時間 周轉時間\n";

p2.SJF();

break;

}

case 3://時間片輪轉

p3=p0;//拷貝一份

int q;

if(p3.isEmpty())

{

cout<<"請先錄入信息\n";

break;

}

else

{

cout<<"請輸入時間片大小";

cin>>q;

cout<<"時間片輪轉\n";

cout<<"進程名 完成時間 周轉時間\n";

p3.RR(q);

break;

}

case 4://優先權

p4=p0;//拷貝一份

if(p4.isEmpty())

{

cout<<"請先錄入信息\n";

break;

}

else

{

cout<<"時間片輪轉\n";

cout<<"進程名 完成時間 周轉時間\n";

p4.priority();

break;

}

default:

cout<<"請選擇目錄中的選項!\n";

break;

}

}

return;

}

9. 急求操作系統「處理機調度演算法」的課程設計的代碼,要用C++或者JAVA,要能編譯運行

以LAMP兄弟連的課程安排來說主要學習一下內容:
1.SpringSecurity:目前最主流的JavaEE安全解決方案,基於Spring。為基於JavaEE企業開發提供全面安全服務。
2.WebSphere:企業級應用伺服器。包含了編寫、運行和監視全天候的工業強度的隨需應變 Web應用程序和跨平台、跨產品解決方案所需要的整個中間件基礎設施。
3.負載均衡:高並發解決方案。能利用一個集群中的多台單機,響應更多的並發請求。
4.分布式系統:由網路互聯的多處理機體系結構上執行任務的系統。可有效提高系統的可擴展性、穩定性和執行效率

10. 求一個操作系統處理機調度先來先服務演算法的代碼,急,要C++的

沒財富回答個吊

閱讀全文

與操作系統調度演算法代碼相關的資料

熱點內容
噴油螺桿製冷壓縮機 瀏覽:579
python員工信息登記表 瀏覽:377
高中美術pdf 瀏覽:161
java實現排列 瀏覽:513
javavector的用法 瀏覽:982
osi實現加密的三層 瀏覽:233
大眾寶來原廠中控如何安裝app 瀏覽:916
linux內核根文件系統 瀏覽:243
3d的命令面板不見了 瀏覽:526
武漢理工大學伺服器ip地址 瀏覽:149
亞馬遜雲伺服器登錄 瀏覽:525
安卓手機如何進行文件處理 瀏覽:71
mysql執行系統命令 瀏覽:930
php支持curlhttps 瀏覽:143
新預演算法責任 瀏覽:444
伺服器如何處理5萬人同時在線 瀏覽:251
哈夫曼編碼數據壓縮 瀏覽:426
鎖定伺服器是什麼意思 瀏覽:385
場景檢測演算法 瀏覽:617
解壓手機軟體觸屏 瀏覽:350