Experiment two, Operation scheduling simulation experiment

Source: Internet
Author: User

Experiment two, Operation scheduling simulation experiment

Internet of Things 201306104128 Wang Yu

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.

2.1 Generation of analog data

1. Allows the user to specify the number of jobs (2-24), 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 time of arrival (0-30) and the desired run time (1-8) for each job.

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

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

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

2. SOURCE program

#include <stdio.h>

#define MAX 24

typedef struct JOB

{

int name; Job name

int Arrivet; Job Arrival time

int Requiret; Job Time

int Startt; Start time

int Endt; End time

int zhouzhuant; Turnaround time = end time-Arrival time

float Answerper; Response than float Zzxs; Turnover factor

char status; Job Status} JCB;

JCB Job[max];

void FIFO ()//first-come-first service algorithm

{

int i,j,k;

JCB temp;

printf ("####### #欢迎进入FIFO模式 ########\n");

do{

printf ("\ n Input Job number: (number in 2-24)");

scanf ("%d", &j); }while (j<2| | J>24);

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

{

printf ("\ n is now the first%d job:", I);

printf ("\ n Job name");

scanf ("%d", &job[i].name);

printf ("Job arrival Time");

scanf ("%d", &job[i].arrivet);

printf ("Job run Time");

scanf ("%d", &job[i].requiret);

Job[i].endt=job[i].requiret+job[i].startt;

printf ("Start Time");

scanf ("%d", &job[i].startt);

printf ("End Time");

scanf ("%d", &job[i].endt);

printf ("Turnaround Time", Endt-arrivet);

}

Sort by job arrival time

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

{

for (k=i+1;k<j;k++)

{

if (Job[k].arrivet<job[i].arrivet)

{

TEMP=JOB[K];

Job[k]=job[i];

Job[i]=temp;

}

if (i==0 | | job[i].arrivet>job[k].endt)

Job[i].startt=job[i].arrivet; else Job[i].startt=job[k].endt;

}

}

printf ("\n* Job * Arrival time * Job Time * Start time * End time * Wait time * turnaround time * turnover factor *\n");

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

{

printf ("\ n%d%d%d,%d%d,%d%f", Job[i].name,job[i].arrivet,job[i].requiret,job[i].startt,job[i].endt,job[i]. Startt-job[i].arrivet,job[i].endt-job[i].arrivet, (Job[i].endt-job[i].arrivet)/job[i].requiret);

}

printf ("\ n");

}

void SJF ()//short Job first algorithm

{

int i,j,k;

JCB temp;

printf ("####### #欢迎进入SJF模式 ########");

do{

printf ("\ n Input Job number: (number in 2-24)");

scanf ("%d", &j);

}

while (j<2| | J>24);

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

{

printf ("\ n is now the first%d job:", I);

printf ("\ n Job name");

scanf ("%d", &job[i].name);

printf ("Job arrival Time");

scanf ("%d", &job[i].arrivet);

printf ("Job run Time");

scanf ("%d", &job[i].requiret);

Job[i].endt=job[i].requiret+job[i].startt;

printf ("Start Time");

scanf ("%d", &job[i].startt);

printf ("End Time");

scanf ("%d", &job[i].endt); }

Sort by job run time

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

{

for (k=i+1;k<j;k++)

{

if (Job[k].requiret<job[i].requiret)

{

TEMP=JOB[K];

Job[k]=job[i];

Job[i]=temp;

}

if (i==0 | | job[i].arrivet>job[k].endt)

Job[i].startt=job[i].arrivet; else Job[i].startt=job[k].endt;

}

}

printf ("\n* Job * Arrival time * Job Time * Start time * End time * Wait time * turnaround time * turnover factor *\n");

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

{

printf ("%d%d%d%d%d%d%f", Job[i].name,job[i].arrivet,job[i].requiret,job[i].endt,job[i].endt-job[i].arrivet, (  Job[i].endt-job[i].arrivet)/job[i].requiret); } printf ("\ n");

}

void Hrrn ()//Response High priority algorithm

{int i,j,k; JCB temp;

printf ("####### #欢迎进入HRRN模式 ########");

do{printf ("\ n Input Job number: (number in 2-24)"); scanf ("%d", &j);

}

while (j<2| | J>24);

for (i=0;i<j;i++)//j is the number of jobs

{

printf ("\ n is now the first%d job:", I);

printf ("\ n Job name");

scanf ("%d", &job[i].name);

printf ("Job arrival Time");

scanf ("%d", &job[i].arrivet);

printf ("Job run Time");

scanf ("%d", &job[i].requiret);

Job[i].endt=job[i].requiret+job[i].startt;

printf ("Start Time");

scanf ("%d", &job[i].startt);

printf ("\ n Job response ratio:%f", 1+ (Job[i].startt-job[i].arrivet)/job[i].requiret);

Job[i].status= ' W ';

}//Response ratio =1+ elapsed time/estimated run time

answerper=1+ (Startt-arrivet)/requiret; Sort by job response ratio

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

{

for (k=i+1;k<j;k++)

{

if (job[k].answerper<job[i].answerper) {temp=job[k];  Job[k]=job[i]; Job[i]=temp;

}

if (i==0 | | job[i].arrivet>job[k].endt)

Job[i].startt=job[i].arrivet;

else Job[i].startt=job[k].endt;

}

printf ("\n* Job * Arrival time * Job Time * Start time * End time * Wait time * turnaround time * response than *\n");

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

{

printf ("%d%d%d%d%d%d%d", job[i].name,job[i].arrivet,job[i].requiret,job[i].startt,job[i].endt,job[i].startt-job [I].arrivet,job[i].endt-job[i].arrivet,job[i].answerper];

}

printf ("\ n");

}

}

void Main ()

{

int i;

printf ("Welcome to use Job scheduling system ****\n\n");

printf ("Please select service algorithm: \n1. FIFO (first come first service);

2.SJF (short job priority), 3.HRRN (response to high priority) \ n ");

scanf ("%d", &i);

Switch (i)

{

Case 1:fifo ();

Break

Case 2:SJF ();

Break

Case 3:hrrn ();

Break

default:printf ("\ n Select error, please select again.");

}

}

Iv. Summary of the experiment

The test is difficult, the main understanding of the scheduling algorithm between the operational relationship, a bit complex, but has a C language three years of learning experience, programming the program is relatively easy

Experiment two, Operation scheduling simulation experiment

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.