Os Exp-5b
Os Exp-5b
Experiment No. 5
AIM: With the increasing number of devotees visiting the temple, the wait time
for 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 .
Implement this using FCFS, SJF (Preemptive, non preemptive) priority and
Round robin scheduling algorithm.
PROBLEM To design and implement a CPU scheduling algorithm for the "Dev
STATEMENT : 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. The CPU scheduling algorithm will be
implemented in the existing "Dev Darshan" system, and will consider the
following factors:
The number of devotees waiting in the queue. The priority of each devotee,
such as senior citizens, children, and differently-
abled individuals.
The time taken by each devotee to complete "Dev Darshan".
The availability of resources, such as the number of "Dev Darshan" counters
and the capacity of the temple. The solution will be tested and evaluated
based on its ability to reduce the wait time for devotees, improve the
utilization of resources, and ensure fairness and equality in the allocation of
resources.
As the number of devotees visiting the temple increases, the waiting time
for "Dev Darshan" has also gone up. Long waiting times cause
inconvenience and discomfort for devotees, making it necessary to find a
better way to manage the queue. To improve this system, different
scheduling methods can be used to organize the queue and reduce waiting
time.
Some of the most effective scheduling algorithms are:
• First-Come-First-Serve (FCFS)
• Shortest Job First (SJF)
• Priority Scheduling
• Round Robin (RR)
Each of these methods works differently and has its own advantages and
disadvantages. This document explains these algorithms in a simple way
and compares their effectiveness in managing the temple queue.
1.First-Come-First-Serve (FCFS)
This is the simplest method, where devotees are served in the order they
arrive. The first person in the queue gets the Darshan first, and others
follow in sequence.
How it works:
✅ Advantages:
❌ Disadvantages:
• Devotees who arrive late may have to wait for a long time.
• If one devotee takes too long, others behind them also get delayed.
In this method, devotees with shorter Darshan times are served first. This
helps in reducing the average waiting time.
Types of SJF:
✅ Advantages:
❌ Disadvantages:
3. Priority Scheduling
In this method, devotees are assigned priority based on certain factors like
age, health condition, or VIP status. Devotees with higher priority are
served first.
✅ Advantages:
❌ Disadvantages:
• Lower-priority devotees may have to wait for a long time.
• If not managed properly, it can be unfair to some devotees.
In this method, each devotee gets a fixed time slot (called a time
quantum) for Darshan. If they complete their Darshan within this time, they
leave the queue. If not, they go back to the end of the queue and wait for
another turn.
How it works:
• A fixed time quantum is set (for example, 5 minutes per devotee).
• Each devotee gets their turn for the given time quantum.
• If a devotee finishes within this time, they leave.
• If not, they rejoin the queue and wait for another round.
• The process repeats until all devotees complete their Darshan.
✅ Advantages:
❌ Disadvantages:
• If the time quantum is too short, it may lead to frequent switching,
making the process inefficient.
• If the time quantum is too long, it may become similar to FCFS.
Which Method is Best?
struct Process {
int id;
int arrivalTime;
int burstTime;
int priority;
int remainingTime;
int waitTime;
int turnaroundTime;
int completed;
};
int main() {
int choice, n, quantum;
struct Process processes[MAX_PROCESSES];
do {
printf("\n==== Dev Darshan Queue Scheduling System ====\n");
printf("1. First Come First Serve (FCFS)\n");
printf("2. Shortest Job First (SJF) - Non-Preemptive\n");
printf("3. Shortest Job First (SJF) - Preemptive\n");
printf("4. Priority Scheduling - Non-Preemptive\n");
printf("5. Priority Scheduling - Preemptive\n");
printf("6. Round Robin\n");
printf("7. Exit\n");
printf("Choose an option: ");
scanf("%d", &choice);
if (choice == 7) {
printf("Exiting program. Thank you!\n");
break;
}
inputProcesses(processes, &n);
if (choice == 6) {
printf("Enter Time Quantum for Round Robin: ");
scanf("%d", &quantum);
}
switch (choice) {
case 1: FCFS(processes, n); break;
case 2: SJF_NonPreemptive(processes, n); break;
case 3: SJF_Preemptive(processes, n); break;
case 4: Priority_NonPreemptive(processes, n); break;
case 5: Priority_Preemptive(processes, n); break;
case 6: RoundRobin(processes, n, quantum); break;
default: printf("Invalid choice! Try again.\n");
}
resetProcesses(processes, n);
} while (1);
return 0;
}
ganttChart[ganttSize] = processes[i].id;
ganttTime[ganttSize] = time;
ganttSize++;
time += processes[i].burstTime;
ganttTime[ganttSize] = time;
if (minIndex == -1) {
time++;
continue;
}
processes[minIndex].waitTime = time -
processes[minIndex].arrivalTime;
processes[minIndex].turnaroundTime = processes[minIndex].waitTime
+ processes[minIndex].burstTime;
processes[minIndex].completed = 1;
totalWait += processes[minIndex].waitTime;
totalTurnaround += processes[minIndex].turnaroundTime;
ganttChart[ganttSize] = processes[minIndex].id;
ganttTime[ganttSize] = time;
ganttSize++;
time += processes[minIndex].burstTime;
completed++;
ganttTime[ganttSize] = time;
if (minIndex == -1) {
time++;
continue;
}
ganttChart[ganttSize] = processes[minIndex].id;
ganttTime[ganttSize] = time;
ganttSize++;
processes[minIndex].remainingTime--;
if (processes[minIndex].remainingTime == 0) {
processes[minIndex].turnaroundTime = time + 1 -
processes[minIndex].arrivalTime;
processes[minIndex].waitTime =
processes[minIndex].turnaroundTime - processes[minIndex].burstTime;
totalWait += processes[minIndex].waitTime;
totalTurnaround += processes[minIndex].turnaroundTime;
completed++;
ganttTime[ganttSize] = time;
if (minIndex == -1) {
time++;
continue;
}
processes[minIndex].waitTime = time -
processes[minIndex].arrivalTime;
processes[minIndex].turnaroundTime = processes[minIndex].waitTime
+ processes[minIndex].burstTime;
processes[minIndex].completed = 1;
totalWait += processes[minIndex].waitTime;
totalTurnaround += processes[minIndex].turnaroundTime;
ganttChart[ganttSize] = processes[minIndex].id;
ganttTime[ganttSize] = time;
ganttSize++;
time += processes[minIndex].burstTime;
completed++;
ganttTime[ganttSize] = time;
if (minIndex == -1) {
time++;
continue;
}
ganttChart[ganttSize] = processes[minIndex].id;
ganttTime[ganttSize] = time;
ganttSize++;
processes[minIndex].remainingTime--;
if (processes[minIndex].remainingTime == 0) {
processes[minIndex].turnaroundTime = time + 1 -
processes[minIndex].arrivalTime;
processes[minIndex].waitTime =
processes[minIndex].turnaroundTime - processes[minIndex].burstTime;
totalWait += processes[minIndex].waitTime;
totalTurnaround += processes[minIndex].turnaroundTime;
completed++;
time++;
}
ganttTime[ganttSize] = time;
ganttChart[ganttSize] = processes[index].id;
ganttTime[ganttSize] = time;
ganttSize++;
ganttTime[ganttSize] = time;
Output:
CONCLUSION: In conclusion, this experiment successfully implemented and analyzed
various CPU scheduling algorithms, including FCFS, SJF (both preemptive
and non- preemptive), and priority scheduling (both preemptive and non-
preemptive), to optimize the "Dev Darshan" system in a temple. Each
algorithm was evaluated based on its ability to minimize wait time, improve
resource utilization, and ensure fairness in queue management. The results
demonstrated that preemptive algorithms, such as SJF Preemptive and
Priority Preemptive, provided better responsiveness and reduced wait times
compared to non-preemptive approaches. However, the choice of algorithm
depends on the specific requirements of the system, such as the need for
fairness, priority handling, and computational efficiency. Overall, the
experiment highlighted the importance of selecting the right scheduling
algorithm.