Experiment Two Job scheduling Simulation program
Major: Commercial Software engineering Name: Zeng No.: 201406114138
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
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? |
|
Third, test methods, procedures and results
1. source program name:pop.cpp executable name:pop.exe
2. principle Analysis and Flowchart
3. Main procedural paragraphs and their explanations:
1 voidFCFS ()2 {3 4 //Calling input functions5 Base();6 7 intI,j,k =0;8 inttemp[ -];9 for(i=0; i<num;i++)Tentemp[i]=i; One A //sort by job arrival time - for(i=0; i<num;i++){ - for(j=i+1; j<num;j++){ the if(job[temp[i]].arrtime>job[j].arrtime) { -K =Temp[i]; -Temp[i] =Temp[j]; -TEMP[J] =K; + } - } + } A at //calculate turnaround time, take ownership turnaround time -job[temp[0]].startime = job[temp[0]].arrtime; -job[temp[0]].finitime = job[temp[0]].startime + job[temp[0]].reqtime; -job[temp[0]]. Tatime = (float) job[temp[0]].finitime-job[temp[0]].arrtime; -job[temp[0]]. Tawtime = job[temp[0]]. tatime/job[temp[0]].reqtime; - for(i=1; i<num;i++){ inJob[temp[i]].startime = job[temp[i-1]].finitime; -Job[temp[i]].finitime = Job[temp[i]].startime +Job[temp[i]].reqtime; toJob[temp[i]]. Tatime = (float) Job[temp[i]].finitime-Job[temp[i]].arrtime; +Job[temp[i]]. Tawtime = Job[temp[i]]. tatime/Job[temp[i]].reqtime; - } the *printf"after sorting by arrival time, the queue is not reached \ n"); $printf"Job name arrival time CPU required time start time end time turnaround time take right turnaround time \ n");Panax Notoginseng - //Output related content the for(i=0; i<num;i++) + { Aprintf"%s\t%d\t\t%d\t%d\t%d\t%f\t%f\n", Job[temp[i]].name,job[temp[i]].arrtime, the Job[temp[i]].reqtime,job[temp[i]].startime,job[temp[i]].finitime,job[temp[i]]. Tatime,job[temp[i]]. Tawtime); + } - $ //calculate average turnaround time, average time to take ownership turnaround $ for(i=0; i<num;i++) - { -Avgtatime + =Job[temp[i]]. Tatime; theAvgtawtime + =Job[temp[i]]. Tawtime; - }Wuyi theprintf"\ n \ nthe average turnaround time =%f\n", avgtatime/num); -printf"average take right turnaround time =%f\n\n", avgtawtime/num); Wu}
4. operation results and Analysis
Experimental Analysis: The experimental results are consistent with the expectations, and the output content is also tested and consistent with the results.
"Operating System" experiment two job scheduling simulation program