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, generation of simulated 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 choose a pseudo-random number to specify the arrival time (0-30) of each job and the desired run time (1-8).
Second, functions 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.
Third, Simulation Data Results Analysis
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.
Four, Experiment Preparation
Serial number |
Prepare content |
Complete situation |
1 |
What is a job? |
|
2 |
What information does a job have? |
|
3 |
In order to facilitate the simulation of the scheduling process, what kind of data structure is used to store and represent the job? JCB |
|
4 |
What are the commonly used job scheduling algorithms in the operating system? |
|
5 |
How to implement the job scheduling algorithm programmatically? |
|
6 |
How is the input of the simulator easier to design and how does the output of the results render better? |
|
Five, Other requirements
1. Complete report, complete content, specification.
2. The experiment must be examined to answer questions about the experiment.
Note: The entry with the * * number indicates the selection.
Ii. contents of the experiment
Complete the design, coding and commissioning work according to the assigned experimental project and complete the experiment report.
three
, experimental environment
You can use TC, or you can choose to use a variety of controls in Windows VB,VC and other visual environment. It is also possible to choose other experimental environments independently.
Four, the experiment
principle and core algorithm reference program segment
Pipettes FCFS algorithm:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define GETPCH (Type) (type*) malloc (sizeof (type))
#define NULL 0
int n;
float t1=0,t2=0;
int times=0;
struct JCB//job control block
{
Char name[10]; Job name
int reachtime; Job Arrival time
int starttime; Job start time
int needtime; Time that the job needs to run
float Super; The response ratio of the job
int finishtime; Job completion time
float Cycletime; Job turnaround Time
float Cltime; Work with right turnaround time
Char state; Job Status
struct JCB *next; struct-Body pointer
}*ready=null,*p,*q;
typedef struct JCB JCB;
void inital ()//Set up the job control block queue, first to first serve the pattern queue
{
int i;
printf ("\ n Enter the number of jobs:");
scanf ("%d", &n);
for (i=0;i<n;i++)
{
P=GETPCH (JCB);
printf ("Enter job Name:");
scanf ("%s", p->name);
Getch ();
p->reachtime=i;
printf ("Job Default arrival time:%d", i);
printf ("\ n Enter the time required to run the job:");
scanf ("%d", &p->needtime);
P->state= ' W ';
p->next=null;
if (ready==null) ready=q=p;
else{
q->next=p;
Q=p;
}
}
}
void disp (jcb* q,int m)//show turnaround time after operation and time of ownership turnaround, etc.
{
if (m==3)//shows the operation of a high response ratio algorithm after scheduling a job
{
printf ("\ nthe job%s is running, estimating its operation: \ n", q->name);
printf ("\ n Job name \ t job requires run time \ n", q->name,p->needtime);
printf ("\ n start the run time \ t complete time \ t turnaround time \ t with the right turnaround time \ t corresponding than \ n");
printf ("%d \ T", q->starttime);
printf ("%d \ T", q->finishtime);
printf ("%f \ T", q->cycletime);
printf ("%f\t", q->cltime);
printf ("%f\n", q->super);
Getch ();
}
else//Show first come first service, shortest job first algorithm operation after scheduling
{
printf ("\ nthe job%s is running, estimating its operation: \ n", q->name);
printf ("\ n start run time \ t complete time \ t turnaround time \ t with right turnaround time \ n");
printf ("%d \ T", q->starttime);
printf ("%d \ T", q->finishtime);
printf ("%f \ T", q->cycletime);
printf ("%f\t", q->cltime);
Getch ();
}
}
void running (JCB *p,int m)//Run Job
{
if (P==ready)//The jobs to be run will be separated from the queue first
{
ready=p->next;
p->next=null;
}
Else
{
Q=ready;
while (Q->NEXT!=P)
q=q->next;
q->next=p->next;
}
p->starttime=times;//Calculate the completion time, turnaround time, etc. after the job is run
P->state= ' R ';
p->finishtime=p->starttime+p->needtime;
P->cycletime= (float) (p->finishtime-p->reachtime);
P->cltime= (float) (p->cycletime/p->needtime);
t1+=p->cycletime;
t2+=p->cltime;
Disp (p,m); Call the disp () function to show that the job is running
times+=p->needtime;
P->state= ' F ';
printf ("\n%s Job completed!\n Press any key to continue ... \ n", p->name);
Free (p); Release a post-run job
Getch ();
}
void super ()//high response ratio for jobs in the calculation queue
{
JCB *padv;
Padv=ready;
do{
if (padv->state== ' W ' &&padv->reachtime<=times)
Padv->super= (float) (times-padv->reachtime+padv->needtime)/padv->needtime;
padv=padv->next;
}while (Padv!=null);
}
void final ()//Last print job average turnaround time, average take right turnaround time
{
float s,t;
t=t1/n; Calculate average turnaround time
s=t2/n; Calculate the average time to take ownership turnaround
Getch ();
printf ("\ n \ nthe job is all done!");
printf ("\n%d average turnaround time for a job is:%f", n,t);
printf ("\n%d of the average working cycle time of the job is:%f\n\n\n", n,s);
}
void Hrn (int m)//high response ratio algorithm
{
JCB *min;
int I,iden;
System ("CLS"); Call system command, clear screen
Inital ();
for (i=0;i<n;i++)
{
P=min=ready;
Iden=1;
Super ();
do{
if (p->state== ' W ' &&p->reachtime<=times)
if (Iden)
{
Min=p;
iden=0;
}
else if (p->super>min->super)
Min=p;
p=p->next;
}while (P!=null);
if (Iden)
{
i--;
times++;
if (times>1000)
{
printf ("\nruntime is too long...error ...");
Getch ();
}
}
Else
{
Running (min,m); Call the running () function
}
}
Final (); Call the running () function
}
void Sjf (int m)//Shortest Job first algorithm
{
JCB *min;
int I,iden;
System ("CLS");
Inital ();
for (i=0;i<n;i++)
{
P=min=ready;
Iden=1;
do{
if (p->state== ' W ' &&p->reachtime<=times)
if (Iden)
{
min=p;iden=0;
}
else if (p->needtime<min->needtime)
Min=p;
p=p->next;
}while (P!=null);
if (Iden)
{
i--;
times++;
if (times>100) {printf ("\nruntime is too long...error");
Getch ();
}
}
else{
Running (min,m); Call the running () function
}
}
Final (); Call the running () function
}
void Fcfs (int m)//First come first service algorithm
{
int I,iden;
System ("CLS");
Inital ();
for (i=0;i<n;i++)
{
P=ready;
Iden=1;
do{
if (p->state== ' W ' &&p->reachtime<=times)
iden=0;
if (Iden) p=p->next;
}while (P!=null&&iden);
if (Iden)
{
i--;
printf ("\ n no process to meet the requirements, wait");
times++;
if (times>100) {printf ("\ nthe time is too long");
Getch ();
}
}
else{
Running (p,m); Call the running () function
}
}
Final (); Call the running () function
}
void Mune ()
{
int m;
System ("CLS");
printf ("\n\n\t\t*********************************************\t\t\n");
printf ("\t\t*\t\t Job Scheduler Main Menu \t\t *\n");
printf ("\t\t*********************************************\t\t\n");
printf ("\n\n\t\t*********************************************\t\t");
printf ("\n\t\t*\t1-first-come-first-serve algorithm \t\t *");
printf ("\n\t\t*\t2. Shortest job Priority Algorithm \t\t *");
printf ("\N\T\T*\T3. Response High Priority Algorithm \t\t *");
printf ("\n\t\t*\t0. Exit program \t\t\t *");
printf ("\n\t\t*********************************************\t\t\n");
printf ("\n\t\t\t\t selection algorithm:");
scanf ("%d", &m);
Switch (m)
{
Case 1:
FCFS (m);
Getch ();
System ("CLS");
Mune ();
Break
Case 2:
SJF (m);
Getch ();
System ("CLS");
Mune ();
Break
Case 3:
Hrn (m);
Getch ();
System ("CLS");
Mune ();
Break
Case 0:
System ("CLS");
Break
Default
printf ("Choose wrong, re-select.");
Getch ();
System ("CLS");
Mune ();
}
}
Main ()//main function
{
Mune ();
return 0;
}
Experiment two job scheduling simulation program