Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Developing the SJF Algorithm For the Shortest Job First (SJF) scheduling algorithm, read the number of processes in the system and their CPU burst times.

Developing the SJF Algorithm For the Shortest Job First (SJF) scheduling algorithm, read the number of processes in the system and their CPU burst times. The scheduling is performed based on non-preemptive and the CPU burst times. Calculate the waiting time and the turnaround time of each of the processes accordingly. Calculate the average waiting time and the average turnaround time. Add enough comments to explain what the code does. We will make the following assumptions about the processes, sometimes called jobs, that are running in the system: 1. Assume arrival time of all processes to be zero, that is ignore the arrival time of the processes in the calculation of their waiting time and the turnaround time.

Process / Burst Time

P1 / 22

P2 / 4

P3 / 7

P4 / 3

// CPU Scheduling Method: Shortest Job First (SJF) #include int main () { int i = 0, j = 0, numProcesses= 0, timeSlice = 0, maxBurstTime = 0, temp = 0; int burstTime[10], backupBurstTime[10], waitTime[10], turnAroundTime[10], responseTime[10]; float avgWaitTime = 0.0, avgTurnAroundTime = 0.0, avgResponseTime = 0.0; printf("\t CPU Scheduling Method: Shortest Job First (SJF) "); printf(" \t Enter the no of processes: "); scanf("%d", &numProcesses); for (i = 0; i < numProcesses; i++) { printf(" \t Enter Burst Time for process %d: ", i + 1); scanf("%d", &burstTime[i]); backupBurstTime[i] = burstTime[i]; } /*Calculate the waiting time, turn-around-time and 'response time' for each process. */ /*... complete the code ...*/

printf(" \t PROCESS\t BURST TIME\t WAITING TIME\t TURNAROUND TIME\t RESPONSE TIME "); for (i = 0; i < numProcesses; i++){ printf("\t P%d \t\t %d \t\t %d \t\t %d \t\t\t %d ", i + 1, backupBurstTime[i], waitTime[i], turnAroundTime[i], responseTime[i]); /*Calculate and print the average waiting time, average turn-around-time, and 'average response time' */

} printf(" \t The Average Waiting time: %.2f ", avgWaitTime / numProcesses); printf(" \t The Average Turnaround time: %.2f ", avgTurnAroundTime / numProcesses); printf(" \t The Average Response time: %.2f ", avgResponseTime / numProcesses); return 0; }

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago