Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Operating Systems Course: Simulation of Scheduling Programs for an Operating System on Linux Machine Create a C or C++ Program of a simulation job scheduler

Operating Systems Course: Simulation of Scheduling Programs for an Operating System on Linux Machine

Create a C or C++ Program of a simulation job scheduler for an operating system. The scheduler will read in a list of jobs from jobs.txt with the relevant information and output the order of completion along with the time of completion for each job and other relevant statistics. Must read in jobs from a text file.

** The Scheduling program will be run from your terminal window. The program will simulate the system monitor of a Batch system like the 1st batch program assignment **

Side Note: (to help anyone answering this posted question, below explains the 1st Batch Program Assignment we had to do)

[Explaination --> The 1st Batch Program assignment required (4) small C programs to be written & placed inside a Directory called Jobs, which was within another Directory called Batch. There was another Console.c Program written, that was saved inside the Batch Directory. The Console.c program was executed from my terminal window, and listed options for each of the other program Jobs loccated inside the jobs directory ]

Program Assignment:

1. Implement the following 3 scheduling Algorithms:

a. First Come, First Served (batch, non preemptive) (FCFS)

b. Shortest Job First (batch, non preemptive) (SJF)

c. Round Robin (preemptive) (RR)

2. Implement Using C or C++ on a Linux machine

3. To run the 3 scheduling algorithms, create a Priority Scheduling Program with menu options that will call the 3 scheduling

programs, (fcfs, sjf, and Round Robin). These are simulation algorithms, that will be run from your terminal window.

4. Below is an example of an input file. This is the input that generated the example output.

ProcessID Arrival cpuBurst Priority

100 0 10 1

101 6 10 1

102 8 4 1

103 12 20 1

104 19 15 1

105 30 5 1

106 35 10 1

4.Below is an example of the way the output should look. In this example each algorithm is run with the same data file (jobs.txt), then the output and statistics are presented. This is a good example to use to test your algorithms and program. For the Round Robin, the time Quanta was 15, I think.

ProcessID Arrival cpuBurst Priority

100 0 10 1

101 6 10 1

102 8 4 1

103 12 20 1

104 19 15 1

105 30 5 1

106 35 10 1

number of jobs in newQ = 7

Terminated Jobs (First Come, First Served)

ProcessId arrival completion

100 0 10

101 6 20

102 8 24

103 12 44

104 19 59

105 30 64

106 35 74

Run Stats

Throughput = 0.09

Average turnaround time = 26.43

Average response time = 15.86

ProcessID Arrival cpuBurst Priority

100 0 10 1

101 6 10 1

102 8 4 1

103 12 20 1

104 19 15 1

105 30 5 1

106 35 10 1

Number of jobs in newQ = 7

Terminated Jobs. (Shortest Job First)

ProcessId arrival completion

100 0 10

102 8 14

101 6 24

104 19 39

105 30 44

106 35 54

103 12 74

Run Stats

Throughput = 0.09

Average turnaround time = 21.29

Average response time = 10.71

ProcessID Arrival cpuBurst Priority

100 0 10 1

101 6 10 1

102 8 4 1

103 12 20 1

104 19 15 1

105 30 5 1

106 35 10 1

Number of jobs in newQ = 7

Terminated Jobs. (Round Robin)

ProcessId arrival completion

100 0 10

101 6 20

102 8 24

104 19 54

103 12 59

105 30 64

106 35 74

Run Stats

Throughput = 0.09

Average turnaround time = 27.86

Average response time = 11.14

5. Below is an example of a routine used to output the run statistics:

void showRunStats(int numJobs, int time)

{

int j;

float tPut, turn, resp;

/* Initialize variables. */

turn = 0.0f;

resp = 0.0f;

/* Calculate turnaround time and waiting time. In this calculation the waiting time is really should be called response time. */

for(j=0;j

turn = turn + (terminated[j].completion - terminated[j].arrival);

resp = resp + (terminated[j].start - terminated[j].arrival);

}

/* Calculate averge values. */

turn = turn/(float)numJobs;

resp = resp /(float)numJobs;

/* Show stats to user. */

printf(" ");

printf("Run Stats ");

/* Throughput. */

tPut = (float)numJobs/(float)time;

printf("Throughput = %.2f ", tPut);

/* Turnaround time. */

printf("Average turnaround time = %.2f ", turn);

/* Waiting time. */

printf("Average response time = %.2f ", resp);

}

6. Below is an example of a routine that reads the job pool data from the file:

int loadJobs(char *filename)

{

FILE *jobs;

char string[80];

int pId, arrival, cpuBurst, priority;

int j;

int nJobs;

/* Open file of jobs to be put in the ready que. */

jobs = fopen(filename, "r");

/* Load the ready que from the file. */

fgets(string, 80, jobs);

printf("%s ", string);

j= 0;

while(fscanf(jobs, "%d %d %d %d", &pId, &arrival, &cpuBurst, &priority) != EOF) {

newQ[j].pId = pId;

newQ[j].arrival = arrival;

newQ[j].cpuBurst = cpuBurst;

newQ[j].priority = priority;

newQ[j].status = NEW;

printf("%d %d %d %d ", newQ[j].pId, newQ[j].arrival, newQ[j].cpuBurst,

newQ[j].priority);

j = j+1;

}

nJobs = j;

printf(" ");

printf("number of jobs in newQ = %d ", nJobs);

fclose(jobs);

return nJobs;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions