For this question, you will write two CPU scheduling algorithms in C. All jobs contain only CPU time, no I/O. You will change the file scheduler.cin the hw1 repo. The code can be compiled with gcc -o jobs jobs.c scheduler.c One helpful method: qsort (jobs, n_jobs, sizeof(Job), jobcmp);

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Question 3: Write Your Own CPU Scheduler
For this question, you will write two CPU scheduling algorithms in C. All jobs contain only CPU time, no I/O. You
will change the file scheduler.c in the hwl repo. The code can be compiled with
gcc -o jobs jobs.c scheduler.c
One helpful method:
qsort (jobs, n_jobs, sizeof (Job), jobcmp);
1
will sort the Job* array from highest priority to lowest priority. The Job struct contains the following:
• idx: the position in which the job arrived (idx 0 arrived first, followed by idx 1, etc)
• priority: the priority of the job in the scheduler (priority 0 highest, followed by priority 1, etc)
• time: the total time required by the job
• run_job: the function that the job runs. These functions are non-associative and must be run in the correct order
to get the correct answer.
Note: the code in the repository currently contains a single test case for jobs and priorities. Different test cases
will be run to make sure your code is correct for any number of jobs with any combination of priorities.
1. Fill in the priority (...) method so that the following are true:
• The job with highest priority runs first. Assume priority 0 is highest, priority 1 is next highest, etc.
• If multiple jobs have the same priority, the job with lowest index will run first among the jobs with this
priority.
• Each job will run for its entirety, e.g. jobs [i] will run for jobs [i]->time.
• job i is run for its entire time limit by calling jobs [i]->run_job (jobs [i]->time).
2. Fill in the priority_rr(...) method so that the following are true :
• Job with highest priority runs first. Assume priority 0 is highest, priority 1 is next highest, etc.
• If multiple jobs have the same priority, all jobs with highest remaining priority run in round-robin.
• When running round-robin, each job runs for a single time_slice
Job i can run for a time_slice amount of time by calling jobs [i]->run_job (time_slice)
• job should not run for longer than its total amount of time. For example, assume job 0 (idx 0) has time 4
and job 1 (idx 1) has time 3. Also assume the time slice is 2. If both jobs have the same priority, this
method should do the following:
a. jobs [0]->run_job (2)
b. jobs [1]->run_job (2)
c. jobs [0]->run_job (2)
d. jobs [1]->run_job (1)
Transcribed Image Text:Question 3: Write Your Own CPU Scheduler For this question, you will write two CPU scheduling algorithms in C. All jobs contain only CPU time, no I/O. You will change the file scheduler.c in the hwl repo. The code can be compiled with gcc -o jobs jobs.c scheduler.c One helpful method: qsort (jobs, n_jobs, sizeof (Job), jobcmp); 1 will sort the Job* array from highest priority to lowest priority. The Job struct contains the following: • idx: the position in which the job arrived (idx 0 arrived first, followed by idx 1, etc) • priority: the priority of the job in the scheduler (priority 0 highest, followed by priority 1, etc) • time: the total time required by the job • run_job: the function that the job runs. These functions are non-associative and must be run in the correct order to get the correct answer. Note: the code in the repository currently contains a single test case for jobs and priorities. Different test cases will be run to make sure your code is correct for any number of jobs with any combination of priorities. 1. Fill in the priority (...) method so that the following are true: • The job with highest priority runs first. Assume priority 0 is highest, priority 1 is next highest, etc. • If multiple jobs have the same priority, the job with lowest index will run first among the jobs with this priority. • Each job will run for its entirety, e.g. jobs [i] will run for jobs [i]->time. • job i is run for its entire time limit by calling jobs [i]->run_job (jobs [i]->time). 2. Fill in the priority_rr(...) method so that the following are true : • Job with highest priority runs first. Assume priority 0 is highest, priority 1 is next highest, etc. • If multiple jobs have the same priority, all jobs with highest remaining priority run in round-robin. • When running round-robin, each job runs for a single time_slice Job i can run for a time_slice amount of time by calling jobs [i]->run_job (time_slice) • job should not run for longer than its total amount of time. For example, assume job 0 (idx 0) has time 4 and job 1 (idx 1) has time 3. Also assume the time slice is 2. If both jobs have the same priority, this method should do the following: a. jobs [0]->run_job (2) b. jobs [1]->run_job (2) c. jobs [0]->run_job (2) d. jobs [1]->run_job (1)
1
#include <stdio.h>
#include <stdlib.h>
#include "jobs.h"
#include "scheduler.h"
// Priority Scheduling -- Jobs with highest priority (lowest number) run first
-- If two jobs with same priority, lower index runs first
void priority(int n_jobs, Job* jobs)
6.
//
8.
9
{
10
}
11
12
// Priority Scheduling with Round Robin --
Jobs with highest priority (lowest number)
13
//
run first
14
//
-- If two jobs have same priority, run both in round robin
Time slice for round robin passed as a parameter
void priority_rr(int n_jobs, Job* jobs, int time_slice)
15
//
--
16
17
{
18
}
19
20
N3
LO
Transcribed Image Text:1 #include <stdio.h> #include <stdlib.h> #include "jobs.h" #include "scheduler.h" // Priority Scheduling -- Jobs with highest priority (lowest number) run first -- If two jobs with same priority, lower index runs first void priority(int n_jobs, Job* jobs) 6. // 8. 9 { 10 } 11 12 // Priority Scheduling with Round Robin -- Jobs with highest priority (lowest number) 13 // run first 14 // -- If two jobs have same priority, run both in round robin Time slice for round robin passed as a parameter void priority_rr(int n_jobs, Job* jobs, int time_slice) 15 // -- 16 17 { 18 } 19 20 N3 LO
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY