Process Scheduling
Process Scheduling
FirstComeFirstServe :
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
completion[0] = burst[0];
turnAround[i] = completion[i];
avgWait += wait[i];
avgTurnAround += turnAround[i];
// Output Table
printf("\nFCFS Scheduling:\n");
int main() {
int n, quantum;
scanf("%d", &n);
scanf("%d", &burst[i]);
process[i] = i + 1;
// FCFS
return 0;
Output :-
Enter number of processes: 3
FCFS Scheduling:
#include <stdlib.h>
#include <limits.h>
burstCopy[i] = burst[i];
order[i] = i;
burstCopy[i] = burstCopy[j];
burstCopy[j] = temp;
temp = order[i];
order[i] = order[j];
order[j] = temp;
}
completion[0] = burstCopy[0];
turnAround[i] = completion[i];
avgWait += wait[i];
avgTurnAround += turnAround[i];
// Output Table
printf("\nSJF Scheduling:\n");
int main() {
int n, quantum;
scanf("%d", &n);
scanf("%d", &burst[i]);
process[i] = i + 1;
// SJF
return 0;
Output :
Enter number of processes: 3
SJF Scheduling:
Round Robin :
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
remaining[i] = burst[i];
if (remaining[i] > 0) {
time += remaining[i];
remaining[i] = 0;
completion[i] = time;
done++;
} else {
time += quantum;
remaining[i] -= quantum;
turnAround[i] = completion[i];
avgWait += wait[i];
avgTurnAround += turnAround[i];
}
// Output Table
int main() {
int n, quantum;
scanf("%d", &n);
scanf("%d", &burst[i]);
process[i] = i + 1;
// Round Robin
scanf("%d", &quantum);
return 0;
Output :
Enter number of processes: 3
Enter burst time for process P1: 24
Priority Scheduling(Non-Preemptive) :
#include <stdio.h>
int p[n];
p[i] = i + 1;
totalWT += waitingTime[i];
totalTAT += turnaroundTime[i];
// Print results
int main() {
int n;
scanf("%d", &n);
scanf("%d", &burst[i]);
scanf("%d", &priority[i]);
return 0;
Output :
Enter number of processes: 5
P1 Burst Time: 10
P1 Priority: 3
P2 Burst Time: 1
P2 Priority: 1
P3 Burst Time: 2
P3 Priority: 4
P4 Burst Time: 1
P4 Priority: 5
P5 Burst Time: 5
P5 Priority: 2
Priority Scheduling :
struct Process {
int id, burst, remaining, priority, arrival, waiting, turnaround, completed;
};
if (p[i].remaining == 0) {
p[i].completed = 1;
p[i].turnaround = currentTime - p[i].arrival;
p[i].waiting = p[i].turnaround - p[i].burst;
totalWT += p[i].waiting;
totalTAT += p[i].turnaround;
completed++;
}
}
}
}
priorityRoundRobin(p, n, timeQuantum);
return 0;
}
Output :
Enter number of processes: 5
P1 Burst Time: 4
P1 Arrival Time: 2
P2 Burst Time: 5
P2 Arrival Time: 1
P3 Burst Time: 8
P3 Arrival Time: 4
P4 Burst Time: 7
P4 Arrival Time: 5
P5 Burst Time: 3
P5 Arrival Time: 3
Priority Scheduling :
Process Priority Burst Time Arrival Time Waiting Time Turnaround
Time
P1 3 4 2 9 13
P2 2 5 1 13 18
P3 2 8 4 16 27
P4 1 7 5 14 21
P5 3 3 3 10 13