Operating system Job Scheduler-operating system

Source: Internet
Author: User
Tags add time

I. Purpose and REQUIREMENTS


1. Purpose of the experiment

(1) Deepen the understanding of the job scheduling algorithm;

(2) Training in program design.

2. Experimental requirements

A simulation program that writes one or more job schedules in a high-level language.

Job scheduler for single-channel batch processing systems. When the job is put into operation, it occupies all the resources of the computer until the job is completed, so it is not necessary to schedule the job to consider whether the resources it needs are met, the time it runs, and so on.

Job scheduling algorithm:

1) The first-come-first service (FCFS) scheduling algorithm, that is, according to the order of operation arrived scheduling. The job that waits the longest in the system is always dispatched first.

2) Short job first (SJF) scheduling algorithm, priority scheduling requires the shortest running time of the job.

3) in response to high-priority (HRRN) scheduling algorithm, set a priority (response ratio) for each job, before scheduling to calculate the priority of each job, priority of the higher priority scheduling. RP (response ratio) = job turnaround time/job run time =1+ job wait time/job run time

Each job is represented by a job control block, JCB can include the following information: Job name, Submission (arrival) time, required run time, required resources, job status, chain pointers, and so on.

The status of the job can be one of waiting for W (wait), running R (run), and completing F (finish) three. The initial state of each job is to wait for W.

First, the generation of simulation data

1. Allows the user to specify the number of jobs (2-24) and the default value is 5.

2. Allows the user to choose to enter the arrival time and the desired run time for each job.

3. (* *) read the above data from the file.

4. (* *) also allows the user to select a pseudo-random number to specify the arrival time (0-30) and the desired run time (1-8) for each job.

Second, the function of the simulation program

1. According to the arrival time and required running time of the simulated data, the FCFS, SJF and HRRN scheduling algorithms are executed, the program calculates the start execution time of each job, the completion time of each job, the turnaround time and the turnaround time (turnover factor).

2. Dynamic demonstration of each scheduling, update the current system time, in the running state and waiting for the corresponding information of each job (job name, arrival time, the desired run time, etc.) for the HRRN algorithm, can show each job response than R in each schedule.

3. (*) allows users to submit new jobs during the impersonation process.

4. (* *) to write and dispatch a multi-channel program system job scheduling simulation program. Only the job scheduling algorithm is required: the first-come-first service-based scheduling algorithm is used. For a multi-channel program system, it is assumed that the resource requirements for each job must be taken into account when scheduling jobs with various resources and quantities in the system.

III. analysis of simulation data results

1. The average turnaround time of each algorithm of the same simulation data is compared with the turnover coefficient.

2. (* *) using a graph or column chart to represent the above data, analysis of the advantages and disadvantages of the algorithm.

Ii. contents of the experiment

#include <iostream> #include <string>using namespace std;//time of data structure struct times {int Hour;int minute;};/       /job struct Job {string jobname;          Job name Time Intime;          Enter time int runtime;       Job estimated runtime time starttime;         Job start time Endtime;        Job end time int cycletime;         Job turnaround time float cltime;      Work with right turnaround time bool Haverun; Whether the};//job has been run average turnaround time float t=0;//job with weight average turnaround time float w=0;//input prompt void Showinput (Job job[],int &n) {cout<< "******** * * Please enter ********* "<<endl;for (int i=0;i<n;i++) {cout<<" Job "<<i+1<<": "<< by Job entry time endl;cout<< "Job Name:";cin>>job[i].jobname;cout<< "Job Entry time:"; scanf ("%d:%d", &job[i].intime.hour, &job[i].intime.minute);cout<< "Job estimated run time:"; Cin>>job[i].runtime;job[i].starttime.hour=0;job[i]. Starttime.minute=0;job[i].endtime.hour=0;job[i].endtime.minute=0;job[i].cycletime=0;job[i].cltime=0;job[i]. haverun=false;cout<< "*********************" <<endl;}} Initialize void Init (Job JoB[],int &n) {for (int i=0;i<n;i++) {job[i].starttime.hour=0;job[i].starttime.minute=0;job[i].endtime.hour=0; Job[i].endtime.minute=0;job[i].cycletime=0;job[i].cltime=0;job[i].haverun=false;} t=0; w=0;} Show time void ShowTime {cout<<time.hour<< ":" <<time.minute;} Calculates the time difference between T1 greater than T2 int Timediff (Times t1,time T2) {return t1.hour*60+t1.minute-(T2.hour*60+t2.minute);} Add Time Timeadd (Time,int addtime) {time.hour+=addtime/60;time.minute+=addtime%60;if (time.minute>=60) { time.hour++;time.minute-=60;} return time;} Compare the size of two times, the first big one returns Truebool comtime (Time T1,time T2) {if (T1.hour>t2.hour) return True;else if (t1.hour==t2.hour &&t1.minute>=t2.minute) return True;elsereturn false;} Display result void Showresult (Job job[],int &n) {cout<< "jobname\tintime\truntime\tsttime\tendtime\t turnaround time (minutes) \ T with right turnaround time "<<endl;cout<<" ******************************************************************* "<< endl;for (int i=0;i<n;i++) {cout<<job[i].jobname<< " \ t "; ShowTime (job[i].intime);cout<<" \ t "<<job[i].runtime<<" \ T "; ShowTime (job[i].starttime); cout << "\ t"; ShowTime (job[i].endtime);cout<< "\ T" <<job[i].cycletime<< "\t\t" <<job[i]. Cltime<<endl;} cout<< "Job average turnaround time: t=" <<t/(n*1.0) <<endl;cout<< "Working with right average turnaround time: w=" <<w/(n*1.0) << Endl;} Find the shortest job in the job subscript int minruntime (Job job[],int &n,time &t) {int min=-1;for (int i=0;i<n;i++) {if (job[i].haverun== False && Comtime (t,job[i].intime) ==true) {min=i;break;}} for (int j=min+1;j<n;j++) if (job[j].haverun==false && job[j].runtime<job[min].runtime && Comtime (t,job[j].intime) ==true) Min=j;return min;} Short job priority job scheduling void SJF (Job job[],int &n) {struct time t;job[0].starttime.hour=job[0].intime.hour;job[0]. Starttime.minute=job[0].intime.minute;job[0].endtime=timeadd (job[0].starttime,job[0].runtime); job[0].haverun= True;job[0].cycletime=timediff (job[0].endtime,job[0].intime); job[0].cltime=job[0].cycletime*1.0/job[0].runtime; T+=job[0].cycletime; W+=job[0].cltime;t=job[0].endtime;while (Minruntime (job,n,t)!=-1) {int i=minruntime (job,n,t), if (Comtime (job[i). intime,t)) Job[i].starttime=job[i].intime;elsejob[i].starttime=t;job[i].endtime=timeadd (Job[i].starttime,job[i]    . Runtime); Job[i].haverun=true;job[i].cycletime=timediff (Job[i].endtime,job[i].intime); Job[i].cltime=job[i].cycletime*1.0/job[i].runtime;    T+=job[i].cycletime; W+=job[i].cltime;t=job[i].endtime;}} Find the first int firstintime (Job job[],int &n) {int min=-1;for (int i=0;i<n;i++) {if (job[i].haverun==false) {min=i) in the job ; break;}} for (int j=min+1;j<n;j++) if (Job[j].haverun==false && comtime (job[min].intime,job[j].intime)) min=j; return min;} First come first service job schedule void FCFS (Job job[],int &n) {struct time t;job[0].starttime.hour=job[0].intime.hour;job[0]. Starttime.minute=job[0].intime.minute;job[0].endtime=timeadd (job[0].starttime,job[0].runtime); job[0].haverun= True;job[0].cycletime=timediff (Job[0].endtime,job[0].intime); Job[0].cltime=job[0].Cycletime*1.0/job[0].runtime; T+=job[0].cycletime; W+=job[0].cltime;t=job[0].endtime;while (Firstintime (job,n)!=-1) {int i=firstintime (job,n), if (Comtime (job[i). intime,t)) Job[i].starttime=job[i].intime;elsejob[i].starttime=t;job[i].endtime=timeadd (Job[i].starttime,job[i]    . Runtime); Job[i].haverun=true;job[i].cycletime=timediff (Job[i].endtime,job[i].intime); Job[i].cltime=job[i].cycletime*1.0/job[i].runtime;    T+=job[i].cycletime; W+=job[i].cltime;t=job[i].endtime;}}   void Main () {cout<< "Please enter the number of jobs:"; int n; Number of Jobs cin>>n; Job *job=new job[n];if (n<=0) {cout<< "input illegal!"; Exit (-1);} Else{showinput (job,n); Cout<<endl;int m = 1;do{cout<< "SELECT Dispatch: 1. First come first serve 2. Short job priority"; int n; cin>>n;//cout <<n<<endl;if (n = = 1) {FCFS (job,n);cout<< "first come first service:" <<endl;showresult (job,n); Cout<<endl ;} Else{init (Job,n); SJF (Job,n); Short job Priority cout<< "short job First:" <<endl;showresult (Job,n);} cout<< "Whether to continue: 1. continue 0. exit"; cin>>m; while (m);} System ("Pause");}

  


Operating system Job Scheduler-operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.