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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started