0% found this document useful (0 votes)
23 views4 pages

Aamod Os 6

Uploaded by

aamod1916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Aamod Os 6

Uploaded by

aamod1916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Aamod Sardeshpande

UID: 2022300097

Experiment No. 6

Program 5

AIM: Rominus pizza wants to implement a pizza scheduling system. Create


individual systems implementing each of the above CPU scheduling
algorithms as follows:
● FCFS: In a pizza delivery system, how does the First-Come-First-Served
(FCFS) scheduling algorithm determine the order in which pizzas are delivered
to customers?
● SJF: In a pizza delivery system, how does the Shortest Job First (SJF)
scheduling algorithm prioritize which pizzas are delivered first based on their
preparation time?
● Round Robin: In a pizza delivery system, how does the Round Robin
scheduling algorithm ensure that each delivery driver gets a fair and equal
chance to deliver pizzas?
● Priority: In a pizza delivery system, how does the Priority scheduling
algorithm prioritize which pizzas are delivered first based on the urgency of
the delivery (e.g. VIP customers, emergency deliveries)?
Also, explain which algorithm will be best suited for the following scenario. Is
it possible to combine the above algorithms to create an even more efficient
algorithm? If yes, then explain how
PROGRAM
AND OUTPUT

#include
<stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
char customerName[50];
int preparationTime;
int priority;
} PizzaOrder;

void fcfs(PizzaOrder *orders, int numOrders) {


printf(" using FCFS scheduling \n");
for (int i = 0; i < numOrders; ++i) {
printf("Delivering pizza to customer: %s\n", orders[i].customerName);
printf("Pizza delivered in %d minutes.\n", orders[i].preparationTime);
}
}

void sjf(PizzaOrder *orders, int numOrders) {


printf("using SJF scheduling...\n");
for (int i = 0; i < numOrders - 1; ++i) {
for (int j = 0; j < numOrders - i - 1; ++j) {
if (orders[j].preparationTime > orders[j + 1].preparationTime) {
PizzaOrder temp = orders[j];
orders[j] = orders[j + 1];
orders[j + 1] = temp;
}
}
}
for (int i = 0; i < numOrders; ++i) {
printf("Delivering pizza to customer: %s\n", orders[i].customerName);
printf("Pizza delivered in %d minutes.\n", orders[i].preparationTime);
}
}

void pri(PizzaOrder *orders, int numOrders) {


printf("using Priority scheduling...\n");
for (int i = 0; i < numOrders - 1; ++i) {
for (int j = 0; j < numOrders - i - 1; ++j) {
if (orders[j].priority < orders[j + 1].priority) {
PizzaOrder temp = orders[j];
orders[j] = orders[j + 1];
orders[j + 1] = temp;
}
}
}
for (int i = 0; i < numOrders; ++i) {
printf("Delivering pizza to customer: %s\n", orders[i].customerName);
printf("Pizza delivered in %d minutes.\n", orders[i].preparationTime);
}
}

void roundrobin(PizzaOrder *orders, int numOrders, int timeSlice) {


printf("using Rmind Robin scheduling \n", timeSlice);
int currentTime = 0;
int currentOrder = 0;
while (currentOrder < numOrders) {
PizzaOrder order = orders[currentOrder];
printf("customer: %s\n", order.customerName);
if (order.preparationTime <= timeSlice) {
printf("Pizza delivered in %d minutes.\n", order.preparationTime);
currentTime += order.preparationTime;
currentOrder++;
} else {
printf("Pizza delivered in %d minutes.\n", timeSlice);
order.preparationTime -= timeSlice;
currentTime += timeSlice;
orders[currentOrder] = order;
currentOrder = (currentOrder + 1) % numOrders;
}
}
}

int main() {
PizzaOrder orders[] = {
{ "AAM1",20, 2},
{ "AAM2",15, 1},
{ "AAM3",25, 3}
};
int numOrders = sizeof(orders) / sizeof(orders[0]);
int timeSlice = 10;

fcfs(orders, numOrders);
sjf(orders, numOrders);
pri(orders, numOrders);
roundrobin(orders, numOrders, timeSlice);

return 0;
}

RESULT: Learnt CPU scheduling algorithms and implemented them .For pizza delivery
system clearly a mix of sjf ,priority and fcfs scheduling algorithms is necessary:-
We define a set of 15 phone calls . for each set we use fcfs . i.e. a set ordered earlier cannot be
delivered after another later set.
Within the set we use priority to create two subsets: premium delivery pizzas & normal
delivery .Within each subset we follow sjf to give each delivery.

You might also like