Lab two job scheduling

Source: Internet
Author: User

Experiment Two Job scheduling Simulation program

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

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

SOURCE program:

#include <stdio.h>
#include <stdlib.h>
#define GETPCH (Type) (type*) malloc (sizeof (type))

struct worktime{
float Tb; Job run time
float Tc; Job completion time
float Ti; Turnaround time
float Wi; Turnaround time with weight
};
struct JCB {//define Job control block JCB
Char name[10]; Job name
float Subtime; Job Submission Time
float runtime; Run time required for the job
char resource; Resource requirements
float Rp; Backup Job Response ratio
Char state; Job Status
struct worktime wt;
struct jcb* link; Chain Pointers
}*jcb_ready=null,*j;
typedef struct JCB JCB;

float t=0;
void sort ()/* Establish a commit time arrangement function for the job */
{
JCB *first, *second;
int insert=0;
if ((jcb_ready==null) | | | ((J->subtime) < (jcb_ready->subtime))) /* Minimum job submission time, insert team first */
{
j->link=jcb_ready;
Jcb_ready=j;
t=j->subtime;
j->rp=1;
}
else/* Job Compare commit time, insert in appropriate location */
{
First=jcb_ready;
second=first->link;
while (Second!=null)
{
if ((J->subtime) < (second->subtime))/* If the insert job is shorter than the current job submission time, */
{/* inserted in front of current job */
j->link=second;
first->link=j;
Second=null;
Insert=1;
}
else/* Insert job with lowest priority number, insert to end of queue */
{
first=first->link;
second=second->link;
}
}
if (insert==0) first->link=j;
}
}

void Sjfget ()/* Gets the shortest job in the queue */
{
JCB *front,*mintime,*rear;
int ipmove=0;
Mintime=jcb_ready;
rear=mintime->link;
while (Rear!=null)
if ((rear!=null) && (t>=rear->subtime) && (mintime->runtime) > (rear->runtime))
{
Front=mintime;
Mintime=rear;
rear=rear->link;
ipmove=1;
}
Else
rear=rear->link;
if (ipmove==1) {
front->link=mintime->link;
mintime->link=jcb_ready;
}
Jcb_ready=mintime;
}
void Hrnget ()/* Gets the highest response job in the queue */
{
JCB *front,*mintime,*rear;
int ipmove=0;
Mintime=jcb_ready;
rear=mintime->link;
while (Rear!=null)
if ((rear!=null) && (t>=rear->subtime) && (MINTIME-&GT;RP) < (REAR-&GT;RP))


{
Front=mintime;
Mintime=rear;
rear=rear->link;
ipmove=1;
}
Else
rear=rear->link;
if (ipmove==1) {
front->link=mintime->link;
mintime->link=jcb_ready;
}
Jcb_ready=mintime;
} void Input ()/* establishes the job control block function */
{int i,num;
printf ("\ n Please enter the number of jobs:");
scanf ("%d", &num);
for (i=0;i<num;i++)
{
printf ("\ n job number no.%d:\n", i+1);
J=GETPCH (JCB);
printf ("\ n Enter job name:");
scanf ("%s", j->name);
printf ("\ n Input job submission time:");
scanf ("%f", &j->subtime);
printf ("\ n Enter job run time:");
scanf ("%f", &j->runtime);
printf ("\ n");
J->state= ' W ';


j->link=null;
Sort (); /* Call the Sort function */
}
}

int space ()
{
int l=0;
jcb* Jr=jcb_ready;
while (Jr!=null)
{
l++;
jr=jr->link;
}
return (L);
}
void disp (jcb* jr,int Select)/* Create job Display function to display the current job */
{
if (select==3)
printf ("\ nthe job service time response is time-of-day turnaround times with right turnaround time \ n");
else printf ("\ nthe time-to-run time for the job service to complete time to turn on turnaround time \ n");
printf ("%s\t", jr->name);
printf ("%.2f\t", jr->runtime);
if (select==3) printf ("%.2f", JR-&GT;RP);
if (J==JR) {
printf ("%.2f\t", JR-&GT;WT. TB);
printf ("%.2f\t", JR-&GT;WT. TC);
printf ("%.2f\t", JR-&GT;WT. Ti);
printf ("%.2f", JR-&GT;WT. Wi);
}
printf ("\ n");

}
void check (int select)/* Create job View function */
{jcb* Jr;
printf ("\ n * * * * Currently running job is:%s", j->name);
/* Displays the currently running job */
Disp (j,select);
Jr=jcb_ready;
printf ("\ n * * * Current ready queue status: \ n");
/* Show ready queue status */
while (Jr!=null)
{
jr->rp= (t-jr->subtime)/jr->runtime;
Disp (jr,select);
jr=jr->link;
}
Destroy ();
}
/*int destroy ()/* Create job Undo function (Job run end, undo job)
{
printf ("\ n Job [%s] completed. \ n", j->name);
Free (j);
}  */
void running (jcb* Jr)/* Set up job readiness function (job run time to, ready state */
{
if (t>=jr->subtime) jr->wt. tb=t; Else JR-&GT;WT. tb=jr->subtime;
JR-&GT;WT. TC=JR-&GT;WT. tb+jr->runtime;
JR-&GT;WT. TI=JR-&GT;WT. tc-jr->subtime;
JR-&GT;WT. WI=JR-&GT;WT. ti/jr->runtime;
T=JR-&GT;WT. Tc;
}
int main ()/* Main function */
{
int select=0,len,h=0;
float sumti=0,sumwi=0;
Input ();
Len=space ();
printf ("\n\t1. FCFS 2.SJF 3.hrn\n\n Please select the Job scheduling algorithm: ");
scanf ("%d", &select);
while ((len!=0) && (jcb_ready!=null))
{h++;
printf ("\ nthe" \ n "Operation%d jobs \ n", h);
J=jcb_ready;
jcb_ready=j->link;
j->link=null;
J->state= ' R ';
Running (j);
SUMTI+=J-&GT;WT. Ti;
SUMWI+=J-&GT;WT. Wi;
Check (select);
if (select==2&&h<len-1) sjfget ();
if (select==3&&h<len-1) hrnget ();
printf ("\ n Press any key to continue ... \ n");
GetChar ();
GetChar ();
}
printf ("\ n \ nthe job has been completed. \ n");
printf ("\ t average turnaround time for this group of jobs:%.2f\n", sumti/h);
printf ("\ t the weighted average turnaround time for this group of jobs:%.2f\n", sumwi/h);
GetChar ();
}

Summary: The various scheduling methods are basic understanding, because operating system operations let me have the opportunity to review the C language and data structure, warm so know new

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.