Os Exp6
Os Exp6
Experiment No. 6
Priority Scheduling:
In thus method, each pizza order is assigned a priority. The highest-priority
orders are delivered first, regardless of when they were placed. While ensuring
fair scheduling by implementing aging (to prevent starvation).
At each point the system finds the highest priority order available (dynamic
processing).
Program 1
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
PROGRAM: Implementation in C: -
FCFS
#include <stdio.h>
struct Pizza {
int id, arrivalTime, burstTime, completionTime, waitingTime,
turnaroundTime;
};
customers[0].completionTime = customers[0].arrivalTime +
customers[0].burstTime;
customers[0].turnaroundTime = customers[0].completionTime -
customers[0].arrivalTime;
customers[0].waitingTime = 0;
customers[i].turnaroundTime = customers[i].completionTime
- customers[i].arrivalTime;
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
customers[i].waitingTime = customers[i].turnaroundTime -
customers[i].burstTime;
}
}
// display results
void displayResults(struct Pizza customers[], int n) {
float totalWT = 0, totalTAT = 0;
printf("\nOptimized Pizza Order:\n");
printf("ID Arrival Burst Completion Turnaround Waiting\n");
int main() {
int n;
printf("Enter number of order: ");
scanf("%d", &n);
fcfsScheduling(customers, n);
displayResults(customers, n);
return 0;
}
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
struct Pizza {
int id, arrivalTime, burstTime, remainingTime,
completionTime, waitingTime, turnaroundTime;
};
if (minIndex == -1) {
currentTime++; //if no pizza is available increment
time
} else {
customers[minIndex].remainingTime--;
currentTime++;
if (customers[minIndex].remainingTime == 0) { // If
pizza preparation is completed
customers[minIndex].completionTime = currentTime;
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
customers[minIndex].turnaroundTime =
customers[minIndex].completionTime -
customers[minIndex].arrivalTime;
customers[minIndex].waitingTime =
customers[minIndex].turnaroundTime -
customers[minIndex].burstTime;
completed++;
}
}
}
}
// display table
void displayResults(struct Pizza customers[], int n) {
float totalWT = 0, totalTAT = 0;
printf("\nOptimized Pizza Order:\n");
printf("ID Arrival Burst Completion Turnaround Waiting\n");
int main() {
int n;
printf("Enter number of customers: ");
scanf("%d", &n);
srtfScheduling(customers, n);
displayResults(customers, n);
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
return 0;
}
ROUND ROBIN
//Round Robin Scheduling
#include <stdio.h>
struct Pizza {
int id, arrivalTime, burstTime, completionTime, waitingTime,
turnaroundTime, remainingTime;
};
int main() {
int n, tq, t = 0, remain, flag;
float totalWT = 0, totalTAT = 0;
printf("Enter number of customers: ");
scanf("%d", &n);
struct Pizza customers[n];
customers[i].completionTime = t;
customers[i].turnaroundTime = customers[i].completionTime -
customers[i].arrivalTime;
customers[i].waitingTime = customers[i].turnaroundTime -
customers[i].burstTime;
totalWT += customers[i].waitingTime;
totalTAT += customers[i].turnaroundTime;
remain--;
} else {
customers[i].remainingTime -= tq;
t += tq;
}
flag = 1;
}
// Add newly arrived processes to the queue
for (int j = 0; j < n; j++) {
if (!visited[j] && customers[j].arrivalTime <= t &&
customers[j].remainingTime > 0) {
queue[rear++] = j;
visited[j] = 1;
}
}
// If the current process still has time left, push it back into
the queue
if (flag && customers[i].remainingTime > 0) {
queue[rear++] = i;
}
// If queue is empty, move time forward
if (front == rear) {
for (int j = 0; j < n; j++) {
if (customers[j].remainingTime > 0) {
queue[rear++] = j;
visited[j] = 1;
break;
}
}
}
}
// Print results
printf("\nOptimized Pizza Order (Round Robin Scheduling):\n");
printf("ID Arrival Burst Completion Turnaround Waiting\n");
for (int i = 0; i < n; i++) {
printf("%d %d %d %d %d %d\n",
customers[i].id, customers[i].arrivalTime,
customers[i].burstTime,
customers[i].completionTime, customers[i].turnaroundTime,
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
customers[i].waitingTime);
}
printf("\nAverage Waiting Time: %.2f\n", totalWT / n);
printf("Average Turnaround Time: %.2f\n", totalTAT / n);
return 0;
}
PRIORITY WITH AGING
#include <stdio.h>
#include <limits.h>
struct Pizza {
int id, arrivalTime, burstTime, remainingTime, priority,
completionTime, waitingTime, turnaroundTime;
};
if (minIndex == -1) {
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
if (customers[minIndex].remainingTime == 0) { // If
completed
customers[minIndex].completionTime = currentTime;
customers[minIndex].turnaroundTime =
customers[minIndex].completionTime -
customers[minIndex].arrivalTime;
customers[minIndex].waitingTime =
customers[minIndex].turnaroundTime -
customers[minIndex].burstTime;
completed++;
}
}
}
}
int main() {
int n;
printf("Enter number of customers: ");
scanf("%d", &n);
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
priorityScheduling(customers, n);
displayResults(customers, n);
return 0;
}
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
RESULT:
FCFS Scheduling:
SJF Scheduling:
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
Priority Scheduling:
BHARATIYA VIDYA BHAVAN’S SARDAR
PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
CONCLUSION: In this experiment, I implemented the algorithms used for CPU Scheduling,
like FCFS, Round Robin, SJF, Priority based etc to design a Pizza delivery
system.
In a pizza delivery system, the choice of scheduling algorithm depends on
the business goals. Round Robin (RR) is ideal for ensuring fairness, as it
gives each order a fixed time slice, preventing any single order from being
delayed too long. Shortest Job First (SJF) focuses on minimizing average
waiting time by delivering orders with shorter preparation times first.
However, First Come, First Serve (FCFS), while simple, can lead to long
delays if a large order arrives early. Priority Scheduling is useful for
handling urgent orders, such as VIP or emergency deliveries, ensuring they
are fulfilled faster than less urgent ones. For a balanced approach, Priority
Scheduling with preemption allows urgent orders to be processed first,
while still ensuring fairness for regular orders.