CPU Scheduling Algorithm
CPU Scheduling Algorithm
int main() {
int n, i;
printf("Enter number of processes: ");
scanf("%d", &n);
wt[0] = 0;
for(i = 1; i < n; i++) {
wt[i] = wt[i - 1] + bt[i - 1];
}
printf("P\tBT\tWT\tTAT\n");
for(i = 0; i < n; i++) {
printf("P%d\t%d\t%d\t%d\n", i + 1, bt[i], wt[i], tat[i]);
}
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter number of processes: ");
scanf("%d", &n);
wt[0] = 0;
for(i = 1; i < n; i++) {
wt[i] = wt[i - 1] + bt[i - 1];
}
printf("P\tBT\tWT\tTAT\n");
for(i = 0; i < n; i++) {
printf("P%d\t%d\t%d\t%d\n", p[i], bt[i], wt[i], tat[i]);
}
#include <stdio.h>
int main() {
int n, i, time, remain, tq;
printf("Enter number of processes: ");
scanf("%d", &n);
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter number of processes: ");
scanf("%d", &n);
2. Analysis of Algorithms
First Come First Serve (FCFS)
Strengths:
Weaknesses:
Can cause high waiting time for short processes (Convoy effect).
No prioritization; not suitable for real-time systems.
Best Use Case: Suitable for batch systems where simplicity is more important than efficiency.
Weaknesses:
Best Use Case: Systems where job lengths can be accurately predicted, such as batch
processing.
Weaknesses:
Higher average waiting and turnaround time if time quantum is not optimized.
More context switches, increasing overhead.
Weaknesses:
Best Use Case: Real-time systems or systems where task importance varies significantly.
3. Conclusion
All four scheduling algorithms offer distinct advantages and disadvantages depending on the
system requirements. FCFS, SJF, and Priority Scheduling yielded the same average waiting and
turnaround times for the test data, but varied in execution time, with Priority being the most
efficient. Round Robin, while slightly less efficient in waiting times, offers superior
responsiveness for interactive systems. In practice, the optimal scheduling policy depends on
the specific needs of the workload, such as fairness, predictability, or responsiveness.