操作系统高响应比优先调度算法模拟实验
生活随笔
收集整理的這篇文章主要介紹了
操作系统高响应比优先调度算法模拟实验
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
從輸入井中選擇作業讀入內存,使其獲得處理器,得到運行的機會,即為作業調度。輸入井中的作業用“作業控制塊”(JCB)標識,為了進行作業調度,將作業控制塊組成一個隊列,這個隊列稱為后備隊列。
模擬實驗中沒有實際作業,作業控制塊中的信息內容只使用了模擬實驗中需要的數據。作業控制塊中包括作業名、作業大小、所需打印機臺數、所需磁帶機數量、作業估計執行時間、作業等待時間、指向下一個作業控制塊的指針等內容。將作業控制塊組成一個隊列,實驗中采用動態鏈表的方式模擬作業的后備隊列。作業控制塊采用結構型數據模擬。
模擬實驗中,主存采用可移動的可變分區管理方法,即只要主存空閑區總和比作業大就可以滿足作業對主存的需求。對打印機和磁帶機這兩種獨占設備采用靜態分配法,即作業執行前必須獲得所需資源,并且執行完才歸還。
實驗中作業的調度采用響應比高者優先算法。響應比為作業的等待時間和作業估計執行時間之比。首先計算出輸入井中滿足條件的作業的響應比,從中選擇響應比最高的一個作業裝入主存儲器,分配資源。由于是模擬實驗,可將作業控制塊出隊裝入主存儲器的工作用輸出作業名模擬,同時修改系統的資源數量。
package OS;import java.util.Arrays; import java.util.Scanner;public class ProcessSchAlg {public static void main(String[] args) {Scanner scn = new Scanner(System.in);int num=Integer.valueOf(scn.nextLine());String initMessage[]=new String[num];for(int i=0;i<initMessage.length;i++) initMessage[i]=scn.nextLine();List Queue=new List(initMessage);Queue.show(0);for(int i=0;i<num;i++) Queue.show(deal(Queue.getProcess()));}public static int deal(Process p){if(p.large>5){System.out.println("The RAM is not enough,Process "+p.name+" require failed!!!");return 0;}if(p.printer>5){System.out.println("The printer is not enough,Process "+p.name+" require failed!!!");return 0;}if(p.tape>5){System.out.println("The tape is not enough,Process "+p.name+" require failed!!!");return 0;}System.out.println("Process "+p.name+" is under operating...");System.out.println("Process "+p.name+" operated successfully!");return p.needTime;} }class List{Process head;Process tail;public List(){head=null;tail=null;}public List(String[] initMessage){head=null;tail=null;for(int i=0;i<initMessage.length;i++) {Process temp =new Process(initMessage[i]);insert(temp);}}public void insert(Process temp){if(head==null){head=temp;head.next=tail;}else if(head.next==null){tail=temp;head.next=tail;}else {tail.next=temp;tail=tail.next;}}public Process getProcess(){double[] lev= new double[10];int index=0;Process p=head;while(p!=null){lev[index]=p.level;index++;p=p.next;}Arrays.sort(lev);p=head;if(p==null)return null;else{if(p.next==null){Process t=new Process();t=head;head=null;return t;}else{Process q=head;if(p.level==lev[9]){Process t=new Process();t=head;head=head.next;return t;}p=p.next;while(p!=null){if(p.level==lev[9]){q.next=p.next;return p;}}}}return null;}public void show(int time){Process p=head;if(p==null) System.out.println("Operate Over!");else {System.out.println("name "+"l\t"+"p\t"+"t\t"+"nT\t"+"wT\t"+"lev");while (p != null) {p.waitTime+=time;p.print();p = p.next;}System.out.println();}} }class Process{String name;int large;int printer;int tape;int needTime;int waitTime;double level;Process next;public Process(){}public Process(String s) {int[] num= new int[4];int index=0;for(int i=0;i<s.length();i++){if(s.charAt(i)==' ') {num[index]=i;index++;}}this.name=s.substring(0,num[0]);this.large=Integer.valueOf(s.substring(num[0]+1,num[1]));this.printer=Integer.valueOf(s.substring(num[1]+1,num[2]));this.tape=Integer.valueOf(s.substring(num[2]+1,num[3]));this.needTime=Integer.valueOf(s.substring(num[3]+1));}public void print(){level=1+((1.0*waitTime)/needTime);System.out.print(name+"\t"+large+"\t"+printer+"\t"+tape+"\t"+needTime+"\t"+waitTime+"\t");System.out.printf("%.2f",level);System.out.println();} }運行結果示范:
總結
以上是生活随笔為你收集整理的操作系统高响应比优先调度算法模拟实验的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sql盲注 解决_解决SQL盲注和跨站脚
- 下一篇: 西南科技大学 SWUST OJ系统942