Experiment two job scheduling simulation program

Source: Internet
Author: User

Experiment two job scheduling simulation program

Wujongzhi 201306104144

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.

Test methods, steps and Results

1. Flowchart

2. SOURCE program

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

Defines the structure of a job schedule

typedef struct jcb{

Char name[10];

Char state;//the status of the job

int arrive_t;//Arrival time

int present_t;//Commit Time

int start_t;//run for a period of time after being preempted by the resource, also the time required

int finish_t;//End Time

int need_t;//operation takes time

int zz_t;//Turnaround Time

int priority; Priority level

int actual_run_t;//Actual run time

Char depend[10];//completed Prerequisite job

struct JCB *next;//points to the next job

}JCB;

JCB job[100],temp[100];

int time=10000,n,flag;//Timer//flag flag Current job Remaining Amount

void Get_value ();

void Paixu (JCB jb[100],int N)

{

int i,j;

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

{

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

if (job[i].arrive_t>job[j].arrive_t)

{

temp[i].arrive_t=job[i].arrive_t;

job[i].arrive_t=job[j].arrive_t;

job[j].arrive_t=temp[i].arrive_t;

temp[i].need_t=job[i].need_t;

job[i].need_t=job[j].need_t;

job[j].need_t=temp[i].need_t;

strcpy (Temp[j].name,job[i].name);

strcpy (Job[i].name,job[j].name);

strcpy (Job[j].name,temp[i].name);

}

}

}

void Paixu1 (JCB jb[100],int N)

{

int i,j;

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

{

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

if (job[i].need_t>job[j].need_t)

{

temp[i].arrive_t=job[i].arrive_t;

job[i].arrive_t=job[j].arrive_t;

job[j].arrive_t=temp[i].arrive_t;

temp[i].need_t=job[i].need_t;

job[i].need_t=job[j].need_t;

job[j].need_t=temp[i].need_t;

strcpy (Temp[j].name,job[i].name);

strcpy (Job[i].name,job[j].name);

strcpy (Job[j].name,temp[i].name);

}

}

}

FCFS (JCB job[100],int N)

{

int i,j=0,now=0;

JCB *p;

flag=n;//number of remaining sign jobs

Paixu (Job,n);

printf ("Output sorted result: \ n");

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

{

printf ("%s\t%d\t%d\t", job[i].name,job[i].arrive_t,job[i].need_t);

printf ("\ n");

}

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

{

p=&job[i];

if (P->arrive_t>now)

now=p->arrive_t;

if (p->state== ' W ' &&p->arrive_t<=now)

{

p->start_t=now;

now+=p->need_t;

p->finish_t=now;

p->zz_t=p->finish_t-p->arrive_t;

P->state= ' F ';

}

printf ("Job name arrival time Start time service time completion turnaround time \ n");

printf ("%s%10d%10d%9d%10d%10d\n", p->name,p->arrive_t,p->start_t,p->need_t,p->finish_t,p->zz_ T);

}

}

SJF (JCB job[100],int N)

{

int i,j=0,now=0;

JCB *p;

flag=n;//number of remaining sign jobs

PAIXU1 (Job,n);

printf ("Output sorted result: \ n");

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

{

printf ("%s\t%d\t%d\t", job[i].name,job[i].arrive_t,job[i].need_t);

printf ("\ n");

}

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

{

p=&job[i];

if (P->arrive_t>now)

now=p->arrive_t;

if (p->state== ' W ' &&p->arrive_t<=now)

{

p->start_t=now;

now+=p->need_t;

p->finish_t=now;

p->zz_t=p->finish_t-p->arrive_t;

P->state= ' F ';

}

printf ("Job name arrival time Start time service time completion turnaround time \ n");

printf ("%s%10d%10d%9d%10d%10d\n", p->name,p->arrive_t,p->start_t,p->need_t,p->finish_t,p->zz_ T);

}

}

PRTF (JCB job[100],int N)

{

PAIXU1 (Job,n);

}

Run (int i)//select the appropriate module to start running

{

printf ("\n\n\n virtual machine starts running: \ n");

Switch (i)

{

Case 1:FCFS (Job, N);

Case 2:SJF (Job, N);

Case 3:PRTF (Job, N);

default:printf ("\ n Run Error! Please check for error!\n");

}

}

void Get_value ()//Get information about the process

{

int num;

printf ("\ nthe total number of jobs?") \ n ");

scanf ("%d", &n);//n indicates the number of jobs

printf ("\ n input process-related information:");

printf ("\nname\t arrive_t \ t need_t\n");//Enter job name, arrival time, time required to run

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

{

scanf ("%s\t%d\t%d", &job[num].name,&job[num].arrive_t,&job[num].need_t); Enter name, arrival time, run time

}

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

{

Job[num].state= ' W ';//status of the job

job[num].actual_run_t=0;//actual run time of the job

}

printf ("Job input completed!") \ n ");

}

Main ()

{

int i,flag1=0;

printf ("Operating system job Simulation Scheduler: \N\T1, FIFO scheduling \n\t2, short process priority scheduling \n\t2, maximum response than priority scheduling \ n");

printf ("Please select: \ n");

scanf ("%d", &i);

if (i<1| | I>3)

{

Flag1=1;

printf ("\ n input error, please enter a number between 1-3:");

}

Else

{

flag1=0;

}

while (flag)//re-enter if the number entered is not between 1-3

{

printf ("Please select: \ n");

scanf ("%d", &i);

if (i<1| | I>3)

{

Flag1=1;

printf ("\ n input error, please enter a number between 1-3:");

}

Else

flag=0;

}

Get_value ();//Get basic information about a job

Run (i);//start running the job

}

3. Operation Results and analysis

Figure 1: First come first service Figure 2: Shortest job priority

4. Summary

I did not fully realize the teacher's request, just made one of the two algorithms, the highest response than the algorithm has not been done, the results are not what I want, but I will continue to improve, but now the homework to hand over.

Experiment two 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.