Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!