Experiment two job scheduling simulation program
Major: Commercial soft second Class No.: 201406114228 Name: Zheng Mingze
First, Experimental Purpose
(1) Deepen the understanding of the job scheduling algorithm;
(2) Training in program design.
Second, experimental content and 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.
(i) Generation of analog 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).
(ii) 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.
(iii) 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.
(iv) Experiment Preparation
Serial number |
Prepare content |
Complete situation |
1 |
What is a job? |
Jobs are a common concept in the operating system. There are two explanations of what a job is. One is to look at the job from the user's point of view, and the other is from the system point of view. From the user's perspective, the definition of the job can be logically abstracted (not precisely), and the organization of the job can be defined from a system perspective. |
2 |
What information does a job have? |
Job number, start run time, arrival time, run time, finish time, wait time, turnaround time, weighted turnaround time |
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 |
A single job uses structs, and multiple jobs use queues |
4 |
What are the commonly used job scheduling algorithms in the operating system? |
① first come first serve ② Short Job Priority ③ response ratio is preferred |
5 |
How to implement the job scheduling algorithm programmatically? |
Single job definition structure, multiple jobs using queues |
6 |
How is the input of the simulator easier to design and how does the output of the results render better? |
Use more prompts to alert the user to input. |
(v) 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.
Third, test methods, procedures and results
1. Source program name: Archive package file (rar or zip) in the source program name Job. C
executable name: Job . EXE
2. principle Analysis and Flowchart
Major overall design issues.
(including storage structure, main algorithm, implementation of key functions, etc.)
3. Main procedural paragraphs and their explanations:
structjcb{Charname[Ten];//Job ID CharStatus//Job Status intArrtime;//Job arrival Time intReqtime;//Job request Time intStartime;//Job start Time intFinitime;//Job completion Time intreRam; intReqtape;//number of tape drives required for the job intReqprinter;//number of printers required for job floatTatime,tawtime; floatPrio;} jobarr[ -],jobfin[ -],job[ -];
//according to the principle of first-come-first service, automatically fill in the job start time, job completion time and other informationvoidAddinfo () {intI=0; for(i=0; I<intjod; i++) { if(i = =0) {Job[i].startime=Job[i].arrtime; Job[i].finitime= Job[i].reqtime +Job[i].arrtime; } Else { if(Job[i].arrtime < job[i-1].finitime) {job[i].startime= job[i-1].finitime; Job[i].finitime= Job[i].startime +Job[i].reqtime; } Else{job[i].startime=Job[i].arrtime; Job[i].finitime= Job[i].startime +Job[i].reqtime; } } } }//to sort the wait queue, follow the principle of first-come-first servicevoidsorting () {structJCB temp; intI=0, j=0; for(i=0; I<intjod; i++) { for(j=i+1; J<intjod; J + +) { if(Job[i].arrtime >job[j].arrtime) {Temp=Job[i]; Job[i]=Job[j]; JOB[J]=temp; }}} addinfo (); }//Insert a job information to the wait queuevoidInsert () {intI=Intjod; printf ("job inserted in section%d:", i+1); printf ("\ n \%d jobs: \ n", i+1); printf ("Enter job Name:"); scanf ("%s",&job[i].name); printf ("Arrival time:"); scanf ("%d",&job[i].arrtime); printf ("Service hours Required:"); scanf ("%d",&job[i].reqtime); printf ("\ n requires memory size:"); scanf ("%d",&Job[i].reram); printf ("number of tape drives required:"); scanf ("%d",&job[i].reqtape); printf ("Number of printers required:"); scanf ("%d",&job[i].reqprinter); Intjod++; sorting (); }//output Wait Queue informationvoidprint () {intI=0; printf ("after sorting by arrival time, the unreachable queue is: \ n"); printf ("\tname\tarrtime\treqtime\tstartime finitime\treqram\treqtape\treqprinter\n"); for(i=0; I<intjod; i++) {printf ("N%d\t%s\t%d\t%d\t%d\t%d\t\t%d\t%d\t%d\n", i+1, Job[i].name,job[i].arrtime,job[i].reqtime,job[i].startime,job[i].finitime,job[i].reram,job[i].reqtape,job [I].reqprinter]; }}//manually enter the wait queuevoidScan () {intI=0; printf ("Number of jobs:"); scanf ("%d",&intjod); for(i=0; I<intjod; i++) {printf ("\ n \%d jobs: \ n", i+1); printf ("Enter job Name:"); scanf ("%s",&job[i].name); printf ("Arrival time:"); scanf ("%d",&job[i].arrtime); printf ("Service hours Required:"); scanf ("%d",&job[i].reqtime); printf ("\ n requires memory size:"); scanf ("%d",&Job[i].reram); printf ("number of tape drives required:"); scanf ("%d",&job[i].reqtape); printf ("Number of printers required:"); scanf ("%d",&job[i].reqprinter); }}
Summary: This experiment requires different algorithms to implement job scheduling simulation program, so I understand the principle of job scheduling, not only let me learn a lot of algorithmic thinking, but also very good to open up our thinking, learn from different angles to think about problems and solve problems. Although the first-come-first service algorithm is done, the program framework is largely unchanged.
Experiment two job scheduling simulation program