Lab two job scheduling

Source: Internet
Author: User

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:

Implementation code:

#include <stdio.h> #include <stdlib.h>typedef struct jcb{//define Process Control block Char NAME[10]; char state; int tt;       Commit time int kt;       Start time int JT;       End time int nt;       Operation takes time int St;     Run for a period of time after being preempted resources, also need time int priority;      Priority float-YT;      Actual run time float jqyt;    Weighted run time char depend[10];    Completion of the premise of the work of the struct JCB *next;        Point to the next job}jcb;int Time=10000,n,flag; Timer//flag flag Current job Remaining Amount Char K;JCB *HEAD=NULL,*P,*Q;RUN_FCFO (JCB *p1) {time=p1->tt>time?p1->tt:time; pri NTF ("\ n now time is%d, start running job%s!\n", Time,p1->name);p rintf ("\nname\ttt\tnt\tjt\tprt\tdepend\tyt\tjqyt\n"); time+=p1->nt; p1->yt=time-p1->tt; p1->jqyt=p1->yt/p1->nt; P1->state= ' F '; p1->jt=time; printf ("%s\t%d\t%d\t%d\t%d\t%s\t%.1f\t%.1f\n", p1->name,p1->tt,p1->nt,p1->jt,p1->priority,p1- &GT;DEPEND,P1-&GT;YT,P1-&GT;JQYT); printf ("\ nthe job%s has run to the end!");%0.1f!\n ", P1->name,p1->yt);}   SATA ()//statistical data {int i; float sum=0,jqsum=0; The total running time and the additionalRight time P=head;  for (i=0;i<n;i++) {sum+=p->yt;  jqsum+=p->jqyt; p=p->next; } printf ("\ n All jobs completed!\n"); printf ("\ n Average turnaround time:%0.2f\n\n Average weighted turnaround time:%0.2f\n", sum/n,jqsum/n);}      FCFS ()//FIFO schedule {int i,j,t;   T as the storage value for the current commit time for (j=0;j<n;j++) {p=head;  t=10000;    for (i=0;i<n;i++)//Find current unfinished job {if (p->tt<t&&p->state== ' W ') {t=p->tt;    Q=p;  Mark a job that is not currently completed} p=p->next; } RUN_FCFO (q); }//Statistics data below SATA ();}     RUN_SJF (JCB *p1) {//p1-<yt=time-p1-<tt+1; if (p1->st==p1->nt) {p1->kt=time;     If it has not been run, determine the run start time} if (p1->st-1==0) {p1->jt=time+1;  If it can end after running, record the current end time} p1->st--; printf ("\ n moment:%d", time); printf ("\nname\ttt\tnt\tst\tprt\n"); printf ("%s\t%d\t%d\t%d\t%d\n", p1->name,p1->tt,p1->nt,p1->st,p1->priority);  if (p1->st==0)//If a job runs at end {p1->yt=p1->jt-p1->tt;  printf ("\n\n\n-----------------------------------------------------\ n"); printf ("-----------------------------------------------------\ n ");  P1->state= ' F ';  printf ("\ n Job%s has been completed, job parameters are as follows: \ n", p1->name);  printf ("\nname\ttt\tnt\tjt\tprt\tdepend\tyt\tjqyt\n");  p1->jqyt=p1->yt/p1->nt; printf ("%s\t%d\t%d\t%d\t%d\t%s\t%.1f\t%.1f\n", p1->name,p1->tt,p1->nt,p1->jt,p1->priority,p1-  &GT;DEPEND,P1-&GT;YT,P1-&GT;JQYT);  printf ("-----------------------------------------------------\ n");  printf ("-----------------------------------------------------\n\n\n"); flag--;    }}SJF ()//short process precedence schedule {int i;       JCB *now=head; Points to the currently running job flag=n;        while (flag) {p=head,q=head; Place p before each loop to point to job header for (i=0;i<n;i++) {if (p->state== ' W ' &&p->tt<=time) {if (q->state== ' W ')     q=q->nt<p->nt?q:p;       Execute short Process priority policy else q=p;  } p=p->next;  } if (q->state!= ' F ') {RUN_SJF (q);   } else {printf ("\ n moment:%d", time);  printf ("\ n No jobs to run, wait for jobs to enter!\n"); } time++; }//Statistics data below SATA (); }run_hrrn (JCB *p1) {//p1-<yt=time-p1-<tt+1; if (p1->st==p1->nt) {p1->kT=time;     If it has not been run, determine the run start time} if (p1->st-1==0) {p1->jt=time+1;  If it can end after running, record the current end time} p1->st--; printf ("\ n moment:%d", time); printf ("\nname\ttt\tnt\tst\tprt\n"); printf ("%s\t%d\t%d\t%d\t%d\n", p1->name,p1->tt,p1->nt,p1->st,p1->priority);  if (p1->st==0)//If a job runs at end {p1->yt=p1->jt-p1->tt;  printf ("\n\n\n-----------------------------------------------------\ n");  printf ("-----------------------------------------------------\ n");  P1->state= ' F ';  printf ("\ n Job%s has been completed, job parameters are as follows: \ n", p1->name);  printf ("\nname\ttt\tnt\tjt\tprt\tdepend\tyt\tjqyt\n");  p1->jqyt=p1->yt/p1->nt; printf ("%s\t%d\t%d\t%d\t%d\t%s\t%.1f\t%.1f\n", p1->name,p1->tt,p1->nt,p1->jt,p1->priority,p1-  &GT;DEPEND,P1-&GT;YT,P1-&GT;JQYT);  printf ("-----------------------------------------------------\ n");  printf ("-----------------------------------------------------\n\n\n"); flag--;    }}HRRN ()//scheduling by priority {int i;       JCB *now=head; Points to the currently running job flag=n; WHile (flag) {p=head,q=head; Place p before each loop to point to job header for (i=0;i<n;i++) {if (p->state== ' W ' &&p->tt<=time) {if (q->state== ' W ')     q=q->priority<p->priority?q:p;       Execute priority priority policy else q=p;  } p=p->next;  } if (q->state!= ' F ') {RUN_HRRN (q);   } else {printf ("\ n moment:%d", time);  printf ("\ n No jobs to run, wait for jobs to enter!\n"); } time++; }//Statistics data below SATA ();} Run (int i)//select the appropriate module to start running {switch (i) {case 1:fcfs (), break, Case 2:SJF (), break, Case 3:hrrn (), Break, Default:print     F ("\ n Run Error! Please check for error!\n"); }}getit ()//Get information about the process {int num; printf ("\ n Total how many jobs?") "); scanf ("%d", &n); printf ("\ n now please enter the details of each process: \ n the tab key between the Items!\n"); printf ("\nname\ttt\tnt\tprt\tdepend\n");  for (num=0;num<n;num++) {p= (JCB *) malloc (sizeof);  if (head==null) {head=p;q=p;}  scanf ("%s\t%d\t%d\t%d\t%s", &p->name,&p->tt,&p->nt,&p->priority,&p->depend);  if (p->tt>time) time=p->tt;  q->next=p;  P->state= ' W '; P->st=p-&gT;nt;  p->yt=0;  p->next=null;          Q=p; Record the position of the current p, prepare for the next definition} printf ("Input completed; \ n");} Startup ()//Run main program {int i; printf ("Operating system job Simulation Scheduler: \N\N\T1, FIFO scheduling; \n\t2, short process priority scheduling; \n\t3, priority scheduling; \ n"); printf ("Please select: \ n"); scanf ("%d", &i);  if (i>3) {printf ("\ n input error, please enter a number between 1-3!\n restart: \ n"); Startup (); } getit (); Run (i);} Main () {printf ("\ n-------------------------job dispatch------------------------\ n"), startup (); printf ("\ n" \ nthe simulation is complete!) \ n ");}

Experiment Summary:

Experimental two relatively difficult, a start, and then asked the students and reference online, only slowly understand understanding.

Lab two job scheduling

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.