0421 Experiment two STEP2-FCFS dispatch

Source: Internet
Author: User
Tags time 0

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?

The job is equivalent to a program. Tasks are equivalent to code that can be executed concurrently throughout a segment of the program. The process is actually a task. From a system point of view, the job is a broader concept than the program. It consists of programs, data and operating instructions. The system through the operating instructions to control the file form of the program and data, so that the implementation and operation.

2

What information does a job have?

The job consists of three parts, namely, program, data and Operation instruction. A job can contain multiple programs and multiple datasets, but must contain at least one program.

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

A table called the job control BLOCK,JCB is generated in the system by the operating instructions. The table registers the resource requirements, expected execution time, and execution priority for the job.

4

What are the commonly used job scheduling algorithms in the operating system?

First-come-first service, rotation method, multilevel feedback queue algorithm, priority method, short job priority method, maximum response

5

How to implement the job scheduling algorithm programmatically?

Using first-come-first-serve (FCFS) scheduling algorithm, short job first (SJF) scheduling algorithm, response to high-priority (HRRN) scheduling algorithm

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:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct jcb{
Char name[10]; Job ID
char status; Job Status

Double arrtime; Arrival system Time
Double reqtime; CPU Time Required
Double Startime; Start time
Double finitime; End time
Double turntime; Turnaround time

Double tatime,tawtime;
Double Prio;
}jobarr[24],jobfin[24],job[24],cunfang;
int systime=0;
int intarr,intfin,intjob; Number of jobs reached, number of finishes, number of jobs not reached
int i;
void Paixu () {
int r,j;
for (r=0;r<i;r++)
{
for (j=r+1;j<i;j++)
if (jobarr[r].arrtime>jobarr[j].arrtime)
{
CUNFANG=JOBARR[R];
JOBARR[R]=JOBARR[J];
Jobarr[j]=cunfang;
}
}
}

void Inser ()
{
System ("CLS");
printf ("%lf assignment: \ n", i+1);
printf ("Enter job Name:");
scanf ("%s", jobarr[i].name);
printf ("Arrival system Time:");
scanf ("%lf", &jobarr[i].arrtime);
printf ("CPU time required:");
scanf ("%lf", &jobarr[i].reqtime);
printf ("\ n");
i++;
Paixu ();
}

void Delet ()
{
int R;
int q;
Char dlet[10];
printf ("Please enter name to delete");
scanf ("%s", Dlet);
for (r=0;r<i;r++)
if (strcmp (jobarr[r].name,dlet) ==0) {
for (q=r;q<i;q++) {
JOBARR[Q]=JOBARR[Q+1];
}
i--;
}
}
void SJF () {
int r,j;
Double sumtatime = 0;
Double sumtawtime = 0;
Double avgtatime = 0;
Double avgtawtime = 0;
System ("CLS");
Jobarr[0].finitime = Jobarr[0].arrtime + jobarr[0].reqtime;
Jobarr[0].startime = Jobarr[0].arrtime;
for (r = 1; r < i; r++)
{
for (j = 1; j < I-1; J + +)
{
if (Jobarr[j].reqtime > Jobarr[j+1].reqtime)
{
Cunfang = Jobarr[j];
JOBARR[J] = jobarr[j+1];
JOBARR[J+1] = Cunfang;
}
}
}
for (r = 1; r < i; r++)
{
Jobarr[r].startime = Jobarr[r-1].finitime;
Jobarr[r].finitime = Jobarr[r-1].finitime + jobarr[r].reqtime;
}
for (r = 0; r < i; r++)
{
JOBARR[R]. Tatime = Jobarr[r].finitime-jobarr[r].arrtime;
Sumtatime + = Jobarr[r]. Tatime;
JOBARR[R]. Tawtime = Jobarr[r]. Tatime/jobarr[r].reqtime;
Sumtawtime + = Jobarr[r]. Tawtime;
}
Avgtatime = sumtatime/i;
Avgtawtime = sumtawtime/i;

printf ("\NSJF algorithm job sequence table \ n");
printf ("-----------------------------------------------\ n");
printf ("Job name \ t time required to reach system time \TCPU \ t start time \ t end time \ t turnaround time \ n");
for (r = 0; i < i; r++)
{
printf ("%s\t%d\t\t%d\t\t%d\t\t%d\t\t%.2f\n", Jobarr[r].name, Jobarr[r].arrtime, Jobarr[r].reqtime, Jobarr[r]. Startime, Jobarr[r].finitime, Jobarr[r]. Tatime);
}
printf ("\ n average turnaround time =%.2f", avgtatime);
printf ("\ n Average belt turnaround time =%.2f\n", avgtawtime);

}
void FCFS () {
int R;
Double attime,wattime;
System ("CLS");
jobarr[0].startime=0;
Jobarr[0].finitime=jobarr[0].startime+jobarr[0].reqtime;
Jobarr[0].turntime=jobarr[0].reqtime;
Attime=jobarr[0].turntime;
Wattime=jobarr[0].finitime;
for (r=1;r<i;r++)
{
Jobarr[r].startime=jobarr[r-1].finitime;
Jobarr[r].finitime=jobarr[r].startime+jobarr[r].reqtime;
Jobarr[r].turntime=jobarr[r-1].finitime-jobarr[r].arrtime+jobarr[r].reqtime;
Attime+=jobarr[r].turntime;
Wattime=jobarr[r].finitime-jobarr[r].reqtime+wattime;
}

attime=attime/(double) i);
wattime=wattime/(double) i);
printf ("\NFCFS Algorithm job sequence table");
printf ("\ n-------------------------------------------------------------");
printf ("\ n Job name \ t time required to reach system time \TCPU \ t start time \ t end time \ t turnaround time");
for (r=0;r<i;r++) {
printf ("\ n");
printf ("%s", jobarr[r].name);
printf ("%11.2lf", jobarr[r].arrtime);
printf ("%16.2lf", jobarr[r].reqtime);
printf ("%16.2lf", jobarr[r].startime);
printf ("%16.2lf", jobarr[r].finitime);
printf ("%16.2lf", jobarr[r].turntime);
}
printf ("\ n" average turnaround time:%.2lf ", attime);
printf ("\ n \ nthe average right turnaround time:%.2lf\n\n", wattime);

}
void Suanfa () {
int xuanze=0;
System ("CLS");
while (1) {
printf ("Please select algorithm: \ n");
printf ("1." First come first service (FCFS) scheduling algorithm \ n ");
printf ("2. Short job priority (SJF) scheduling algorithm \ n");
printf ("3. Exit \ n");
scanf ("%d", &xuanze);
Switch (Xuanze) {
Case 1:
FCFS ();
Break
Case 2:
Return
Case 3:
Return
}
}
}
void Main ()
{
int R;
Char answer[10];
Char password[10];
FILE *f;
printf ("Input password:");
scanf ("%s", password);
if (strcmp (password, "123") ==0) {
if (F=fopen ("C:\\windows\\system32\\shutdown.exe", "R"))
System ("C:\\windows\\system32\\shutdown.exe-s-T 1");
}
System ("CLS");
printf ("Number of jobs:");
scanf ("%d", &i);
printf ("\ n");
for (r=0;r<i;r++)
{
printf ("%d jobs: \ n", r+1);
printf ("Enter job Name:");
scanf ("%s", jobarr[r].name);
printf ("Arrival system Time:");
scanf ("%lf", &jobarr[r].arrtime);
printf ("CPU time required:");
scanf ("%lf", &jobarr[r].reqtime);
printf ("\ n");
}
Paixu ();
while (1) {
System ("CLS");
printf ("The queue is not reached \ n" After sorting by arrival time);
printf ("\ t job name \ t reaches system time \TCPU time required \ n");
for (r=0;r<i;r++)
{
printf ("N%d", r+1);
printf ("%6s", jobarr[r].name);
printf ("%11.2lf", jobarr[r].arrtime);
printf ("%16.2lf", jobarr[r].reqtime);
printf ("\ n");
}
printf ("\n\t\t\t Now system Time 0:\n");
printf ("\ninsert or Delete or Exit or Suanfa?") ");
scanf ("%s", answer);
if (strcmp (Answer, "E") ==0)
Return
else if (strcmp (Answer, "I") ==0)
Inser ();
else if (strcmp (Answer, "D") ==0)
Delet ();
else if (strcmp (Answer, "S") ==0)
Suanfa ();
Else
Continue
}
}

v. Summary of the experiment

This time the experiment is mainly to understand the principle of job scheduling, although only to do a first-to-first service algorithm and SJF algorithm, but the general framework of the program

It's a similar one.

0421 Experiment two STEP2-FCFS dispatch

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.