Job Scheduling Simulation Program

Source: Internet
Author: User

Experiment two job scheduling simulation program

Major: Internet of Things project name: Huang No.: 201306104145

First, the purpose of the experiment

(1) Deepen the understanding of the job scheduling algorithm;

(2) Training in program design.

Second, the contents and requirements of the experiment

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.

1, the 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).

2, 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.

3. 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.

4. 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.

Test methods, steps and Results

1. SOURCE program Name: Compressed package file (rar or zip) source program name HM.C

Executable Program Name: Hm.exe

2. Principle Analysis and Flowchart:

Storing data in the form of a structural body

3. Main procedural paragraphs and their explanations:

#include <stdio.h>

#include <stdlib.h>

int i,k,num,m,n;

#define N 25

struct jcb{

Char name[10]; Job name

float at; Job Submission Time

float RT; Job Run Time

float S; Start Time

float F; Time to complete

float T; Turnaround Time

float W; turnaround time with weight

}jcb[n],temp;

void input ()// user Input module

{

int i;

do{

printf ("\ n Please enter the number of jobs (2-24):");

scanf ("%d", &num);

printf ("\ n");

if (num<2| | num>24) printf (" input error, please re-enter!") \ n ");

}

while (num<2| | NUM>24);

for (i=0;i<num;i++)

{

printf (" %d job name :", i+1);

scanf ("%s", &jcb[i].name);

printf ("\ n commit time :");

scanf ("%f", &jcb[i]. at);

printf ("\ n run time :");

scanf ("%f", &jcb[i]. RT);

printf ("\ n");

}

}

void output ()// Output Module

{

float numt=0,numw=0,avgt=0,avgw=0;

printf ("*****************************************************************\n");

printf (" Job name submission time run time start time completion time turnaround time with right turnaround time \ n");

for (i=0;i<num;i++)

{

printf ("%-9s%-9.0f%-9.0f%-10.0f%-10.0f%-9.0f%-9.2f%\n", Jcb[i].name,jcb[i]. At,jcb[i]. Rt,jcb[i]. S,jcb[i]. F,jcb[i]. T,jcb

[i]. W);

Numt=numt+jcb[i]. T

Numw=numw+jcb[i]. W

}

printf ("*****************************************************************\n");

Avgt=numt/num;

Avgw=numw/num;

printf (" average turnaround time:%.2f\n", AVGT);

printf ("\ n");

printf (" average turnaround time with right:%.2f\n", AVGW);

printf ("\ n");

}

void sort ()

{

int i,j;

for (j=0;j<num;j++)/* bubble sort * /

{

for (i=0;i<num-j-1;i++)

{

if (Jcb[i]. AT>JCB[I+1]. at)

{

Temp=jcb[i];

JCB[I]=JCB[I+1];

Jcb[i+1]=temp;

}

}

}

}

void Run ()

{

for (k=0;k<num;k++)

{

if (k==0)

{

JCB[K]. S=JCB[K]. at;

JCB[K]. F=JCB[K]. AT+JCB[K]. RT;

}

Else

{

if (Jcb[k]. AT>=JCB[K-1]. F) /* The current job has ended and the next job has not arrived or is just arrived * /

{

JCB[K]. S=JCB[K]. at;

JCB[K]. F=JCB[K]. AT+JCB[K]. RT;

}

else/* The current job is not completed, the next job has arrived * /

{

JCB[K]. S=JCB[K-1]. F

JCB[K]. F=JCB[K-1]. F+JCB[K]. RT;

}

}

}

for (k=0;k<num;k++)

{

JCB[K]. T=JCB[K]. F-JCB[K]. at;

JCB[K]. W=JCB[K]. T/JCB[K]. RT;

}

}

void Fcfs ()/* first come first service * /

{

Run ();

printf ("\t\t\t first to First run:\ n");

Output ();/* outputs Job schedule table * /

}

void SJF ()/* Short Job Priority * /

{

int a[20];

int p,q;

for (i=0;i<num;i++)

{

m=0;

if (i==0) jcb[i]. F=jcb[i]. At+jcb[i]. RT;

else Jcb[i]. F=JCB[I-1]. F+jcb[i]. RT;

for (n=i+1;n<num;n++)

{

if (Jcb[n]. At<=jcb[i]. F)// determine how many jobs arrive after each job is completed

{

A[m]=n;

m++;

}

}

for (p=0;p<m;p++)// to bubble sort the arrival job

{

for (q=0;q<m-p-1;q++)

{

if (Jcb[a[q]]. RT>JCB[A[Q+1]]. RT)

{

TEMP=JCB[A[Q]];

JCB[A[Q]]=JCB[A[Q+1]];

Jcb[a[q+1]]=temp;

}

}

}

}

Run ();

printf ("\t\t\t short Job First run:\ n");

Output ();

}

void HRRF ()/* Highest response ratio priority * /

{

int a[20];

int p,q;

for (i=0;i<num;i++)

{

m=0;

if (i==0) jcb[i]. F=jcb[i]. At+jcb[i]. RT;

else Jcb[i]. F=JCB[I-1]. F+jcb[i]. RT;

for (n=i+1;n<num;n++)

{

if (Jcb[n]. At<=jcb[i]. F)// determine how many jobs arrive after each job is completed

{

A[m]=n;

m++;

}

}

for (p=0;p<m;p++)// to bubble sort the arrival job

{

for (q=0;q<m-p-1;q++)

{

if (i==0 && p==0 && q==0)

{

if (((jcb[a[q]-1). F-JCB[A[Q]]. at)/jcb[a[q]]. RT) < ((Jcb[a[q]]. F-JCB[A[Q+1]]. at)/jcb[a[q+1]]. RT))

{

TEMP=JCB[A[Q]];

JCB[A[Q]]=JCB[A[Q+1]];

Jcb[a[q+1]]=temp;

}

}

Else

{

if (((jcb[a[q-1)]. F-JCB[A[Q]]. at)/jcb[a[q]]. RT) < ((Jcb[a[q]]. F-JCB[A[Q+1]]. at)/jcb[a[q+1]]. RT))

{

TEMP=JCB[A[Q]];

JCB[A[Q]]=JCB[A[Q+1]];

Jcb[a[q+1]]=temp;

}

}

}

}

}

Run ();

printf ("\t\t\t maximum response ratio First run:\ n");

Output ();

}

Main ()

{

int n;

do{

Input ();

printf (" Job Scheduler simulator \ n");

printf ("0:exit quit \ n \ nthe");

scanf ("%d", &n);

printf ("\ n");

if (n==0) continue;

Else

{

Sort ();

FCFS ();

Sort ();

SJF ();

Sort ();

HRRF ();

}

}

while (n!=0);

}

4. Operation Results and analysis

When entering the job book, when the work book is greater than or less than 2 will prompt and re-enter:

After entering the number of jobs, the number of users will be required to submit and run for the corresponding number of jobs:

Operation Result:

Iv. Summary of the experiment

This job requires three scheduling methods, because the method is not familiar at the beginning of the scheduling, do not know where to write, and finally spent a lot of time finally written code and realized the function, during the discovery of three kinds of scheduling there are some of the same place, so that through their common ground to finish the program.

Job Scheduling Simulation Program

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.