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 choose a pseudo-random number to specify the arrival time (0-30) of each job and the desired run time (1-8).
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.
Iv. 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
#include <stdio.h>
typedef struct jcb{
Char name[10];
Char state;
int tt; Arrival time
int kt; Start time
int JT; End time
int NT; Time to run
int ZZT; Turnaround time
int DDT; Wait time
int Staut; State
float Dqzzt; Turnaround time with weight
float Xyb; Response ratio
}JCB;
JCB Work[5];
int n;
float pzzt=0; Average turnaround time
float pdqt=0; Average time to take ownership turnaround
Getit ()
{
int num,aaa=0;
printf ("\ nthe total number of jobs?") ");
scanf ("%d", &n);
printf ("\ n now please enter details for each process: \ n");
printf ("Time required for process name arrival time \ n");
for (aaa=0;aaa<n;aaa++)
{
scanf ("%s", &work[aaa].name);
scanf ("%d", &work[aaa].tt);
scanf ("%d", &work[aaa].nt);
}
printf ("input completed; \ n");
printf ("The information you have entered is: \ n");
printf ("Time required for process name arrival time \ n");
for (num=0;num<n;num++)
{
printf ("%s\t%d\t%d\t\n", Work[num].name,work[num].tt,work[num].nt);
}
}
FCFS ()
{
int i,j;
JCB temp;
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (WORK[J].TT<WORK[I].TT)
{
TEMP=WORK[J];
Work[j]=work[i];
Work[i]=temp;
}
}}
for (i=0;i<n;i++)
{
if (i==0)
{
Work[i].kt=work[i].tt;
}
Else
WORK[I].KT=WORK[I-1].JT;
Work[i].jt=work[i].kt+work[i].nt;
Work[i].zzt=work[i].jt+work[i].tt;
work[i].dqzzt= (float) Work[i].zzt/work[i].nt;
}
for (i=0;i<n;i++)
{
printf ("Job scheduling result is: \ n");
printf ("Process name arrival time required time start time end time turnaround time with right turnaround time \ n");
printf ("\t%s\t%d\t%d\t%d\t%d\t%d\t%f\n", Work[i].name,work[i].tt,work[i].nt,work[i].kt,work[i].jt,work[i].zzt, WORK[I].DQZZT);
}
}
SJF ()
{
int i,j;
JCB temp;
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (Work[j].nt<work[i].nt)
{
TEMP=WORK[J];
Work[j]=work[i];
Work[i]=temp;
}
}}
for (i=0;i<n;i++)
{
if (i==0| | WORK[I].TT>WORK[I-1].JT)
{
Work[i].kt=work[i].tt;
}
Else
WORK[I].KT=WORK[I-1].JT;
Work[i].jt=work[i].kt+work[i].nt;
Work[i].zzt=work[i].jt+work[i].tt;
work[i].dqzzt= (float) Work[i].zzt/work[i].nt;
}
for (i=0;i<n;i++)
{
printf ("Job scheduling result is: \ n");
printf ("Process name arrival time required time start time end time turnaround time with right turnaround time \ n");
printf ("\t%s\t%d\t%d\t%d\t%d\t%d\t%f\n", Work[i].name,work[i].tt,work[i].nt,work[i].kt,work[i].jt,work[i].zzt, WORK[I].DQZZT);
}
}
JCB Hrrf2 (int k)
{
JCB Temp,zzjcb,work1[5];
int i,j;
for (i=1;i<n;i++)
{
Work1[i]=work[i];
}
for (i=1;i<n;i++)
{
if (work1[i].state==0)
{
Work1[i].ddt=work1[k].jt-work1[i].tt;
work1[i].xyb= (float) (Work1[i].ddt+work1[i].nt)/work1[i].nt;
}
Else
work[i].xyb=0;
}
for (i=1;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (WORK1[J].XYB>WORK1[I].XYB)
{
TEMP=WORK1[J];
Work1[j]=work1[i];
Work1[i]=temp;
}
}}
ZZJCB=WORK1[1];
return (ZZJCB);
}
HRRF1 ()
{
int i,j;
JCB temp;
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (WORK[J].TT<WORK[I].TT)
{
TEMP=WORK[J];
Work[j]=work[i];
Work[i]=temp;
}
}}
Work[0].kt=work[0].tt;
Work[0].jt=work[0].kt+work[0].nt;
Work[0].zzt=work[0].jt+work[0].tt;
work[0].dqzzt= (float) Work[0].zzt/work[0].nt;
work[0].state=1;
for (i=1;i<n;i++)
{
Work[i]=hrrf2 (i-1);
if (WORK[I].TT>WORK[I-1].JT)
{
Work[i].kt=work[i].tt;
}
Else
WORK[I].KT=WORK[I-1].JT;
Work[i].jt=work[i].kt+work[i].nt;
Work[i].zzt=work[i].jt+work[i].tt;
work[i].dqzzt= (float) Work[i].zzt/work[i].nt;
work[i].state=1;
}
for (i=0;i<n;i++)
{
printf ("Job scheduling result is: \ n");
printf ("Process name arrival time required time start time end time turnaround time with right turnaround time \ n");
printf ("\t%s\t%d\t%d\t%d\t%d\t%d\t%f\t\n", Work[i].name,work[i].tt,work[i].nt,work[i].kt,work[i].jt,work[i].zzt , WORK[I].DQZZT);
}
}
Select ()
{
int i;
printf ("\ n-------------------------Good Life starts here!------------------------\ n");
printf ("Operating system job Simulation Scheduler: \N\N\T1, FIFO scheduling, \N\T2, short process priority scheduling, \N\T3, maximum response than priority scheduling; \ n");
printf ("Please select: \ n");
scanf ("%d", &i);
if (i==1)
{
printf ("\ n you have selected FIFO scheduling \ n");
Getit ();
FCFS ();
}
if (i==2)
{
printf ("\ n you selected a short process priority dispatch \ n");
Getit ();
SJF ();
}
if (i==3)
{
printf ("\ n you selected the highest response than priority dispatch \ n");
Getit ();
Hrrf1 ();
}
if (i>3)
{
printf ("\ n input error, please enter a number between 1-2!\n start again: \ n");
}
for (i=0;i<n;i++)
{
Pzzt=work[i].zzt+pzzt;
}
pzzt=pzzt/n;
for (i=0;i<n;i++)
{
PDQT=WORK[I].DQZZT+PDQT;
}
pdqt=pdqt/n;
printf ("Average turnaround time with right turnaround time \ n");
printf ("%f\t%f\t\n", PZZT,PDQT);
}
Main ()
{
Select ();
}
Iii. Summary of the experiment
In this experiment, I have defined a structure in which there is an experiment to show or a member that needs to be calculated, such as the time of arrival, execution time, time of ownership, and so on. Then initialize a struct array, because the teacher says it can support five jobs, so my array size is 5. Write the time encountered some problems, the most funny is the/T, because this/t I turned to the class of a great God, and then two people debugging a class or see no problem, is in the input of the job will always require more input a job, finally deleted the last T/s problem is solved. There are some other problems, but finally they are solved.
11 11 Experiment Two operation scheduling simulation experiment