Expt 05 CPUScheduling
Expt 05 CPUScheduling
Experiment 5
PROBLEM With the increasing number of devotees visiting the temple, the wait time for
STATEMENT : "Dev Darshan" has become longer, causing inconvenience to the devotees. This
has resulted in a need for a more efficient system that can manage the waiting
queue and reduce the wait time for "Dev Darshan".
Goal: To design and implement a CPU scheduling algorithm for the "Dev
Darshan" system in the temple that can effectively manage the waiting queue,
minimize the wait time for devotees, and improve the overall experience of
visiting the temple.
Scope: The CPU scheduling algorithm will be implemented in the existing
"Dev Darshan" system, and will consider the following factors:
1. The number of devotees waiting in the queue.
2. The priority of each devotee, such as senior citizens, children, and
differently-abled individuals.
3. The time taken by each devotee to complete "Dev Darshan".
4. The availability of resources, such as the number of "Dev Darshan"
counters and the capacity of the temple.
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Give the solution with an example of Dev darshan CPU scheduling algorithm .
Write a program to simulate the following non-preemptive CPU scheduling
algorithms to find turnaround time and waiting time.
a) FCFS
b) SJF
c) Round Robin
d) Priority scheduling
struct Devotee {
int id;
int arrival_time;
int burst_time;
int completion_time;
int waiting_time;
int turnaround_time;
int priority;
};
completion_time[0] = devotees[0].arrival_time +
devotees[0].burst_time;
devotees[0].turnaround_time = completion_time[0] -
devotees[0].arrival_time;
devotees[0].waiting_time = devotees[0].turnaround_time -
devotees[0].burst_time;
devotees[i].turnaround_time = completion_time[i] -
devotees[i].arrival_time;
devotees[i].waiting_time = devotees[i].turnaround_time
- devotees[i].burst_time;
}
}
int remaining_burst_time[n];
for (int i = 0; i < n; i++) {
remaining_burst_time[i] = devotees[i].burst_time;
devotees[i].waiting_time = 0;
}
int time = 0;
int completed = 0;
while (completed < n) {
for (int i = 0; i < n; i++) {
if (remaining_burst_time[i] > 0) {
int time_slice = (remaining_burst_time[i] >
quantum) ? quantum : remaining_burst_time[i];
remaining_burst_time[i] -= time_slice;
time += time_slice;
if (remaining_burst_time[i] == 0) {
completed++;
devotees[i].completion_time = time;
devotees[i].turnaround_time =
devotees[i].completion_time - devotees[i].arrival_time;
devotees[i].waiting_time =
devotees[i].turnaround_time - devotees[i].burst_time;
}
}
}
}
calculateTimes(devotees, n);
int main() {
int n;
printf("Enter number of devotees: ");
scanf("%d", &n);
struct Devotee devotees[n];
printf("Enter devotee details (ID ArrivalTime BurstTime
Priority):\n");
for (int i = 0; i < n; i++) {
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
fcfs(devotees, n);
sjf(devotees, n);
int quantum;
printf("\nEnter time quantum for Round Robin: ");
scanf("%d", &quantum);
roundRobin(devotees, n, quantum);
priorityScheduling(devotees, n);
return 0;
}
OUTPUT:
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India