OSY Notes Vol 2 (4th Chapter) - Ur Engineering Friend
OSY Notes Vol 2 (4th Chapter) - Ur Engineering Friend
Process
2. Data: This includes variables, constants, and other data required by the
program during execution.
Scheduling Categories
Preemptive Scheduling
Non-preemptive Scheduling
Preemptive and non-preemptive scheduling are two types of process scheduling
mechanisms used by operating systems to manage the execution of multiple
processes in a multitasking environment.
These mechanisms determine how the operating system decides which process
to run and for how long.
1. Preemptive Scheduling:
Advantages:
Enhances responsiveness and reduces latency for high-priority tasks.
Allows for better utilization of system resources by swiftly responding to
new tasks or higher-priority processes.
Disadvantages:
Requires careful handling to prevent race conditions and ensure data
consistency.
Context switching (switching between processes) involves overhead,
potentially affecting system performance.
Advantages:
Disadvantages:
1. First-Come-First-Served (FCFS):
Processes are scheduled in the order they arrive in the ready queue.
Simple and easy to implement, but may lead to longer waiting times for
shorter processes (convoy effect).
Processes are scheduled based on their burst time (the time taken to
complete their execution).
Minimizes average waiting time and is optimal for minimizing waiting
time for the shortest processes.
However, it requires knowledge of the burst times in advance, which
may not always be available.
5. Priority Scheduling:
6. Priority Aging:
Divides the ready queue into multiple separate queues with different
priorities.
Each queue can have its own scheduling algorithm.
Processes move between queues based on their characteristics or
system-defined criteria.
9. Lottery Scheduling:
Advantages :
Disadvantages:
1. Convoy Effect : FCFS can suffer from the convoy effect, where shorter
processes are stuck behind a long-running process. This increases the average
waiting time, especially for shorter processes.
2. High Average Waiting Time : The average waiting time can be relatively
high, especially if shorter processes arrive after longer processes. This can lead
to suboptimal performance in terms of response time.
4. Not Suitable for Real-Time Systems : FCFS is not suitable for real-time
systems where strict timing requirements need to be met. It doesn't prioritize
processes based on their urgency or importance.
Example -:
Shortest Job First ( SJF )
1. Non-Preemptive SJF:
The operating system schedules the process with the shortest burst time
first.
When a new process arrives, its burst time is compared with the
remaining burst times of other processes in the ready queue. The process
with the shortest burst time is selected to run next.
If a new process arrives with a shorter burst time than the remaining
time of the currently running process, the operating system preempts the
running process and schedules the new process.
The algorithm compares the remaining burst times of all processes and
selects the one with the shortest remaining burst time to run next.
Advantages of SJF:
1. Optimal Average Waiting Time : SJF provides the minimum average
waiting time among all scheduling algorithms. It gives priority to shorter jobs,
which minimizes the overall waiting time.
2. Efficient Utilization of CPU : When the process with the shortest burst time
is scheduled first, it optimizes CPU utilization by executing processes quickly.
Disadvantages of SJF:
3. Unrealistic Assumption : SJF assumes that the burst time of each process is
known in advance, which is not always the case in real-world scenarios.
Example -:
Round Robin
Time Sharing is the main emphasis of the algorithm. Each step of this algorithm
is carried out cyclically. The system defines a specific time slice, known as a
time quantum.
1. Initialization: Create a queue to hold the processes that are ready to execute.
Each process is assigned a fixed time quantum (time slice) that determines how
long it can run on the CPU before being moved to the back of the queue.
4. Execution: The selected process is allowed to execute on the CPU until its
time quantum expires or it voluntarily releases the CPU, such as when it
performs an I/O operation or finishes its execution.
Example -:
Priority Scheduling
Advantages:
Disadvantages:
Deadlock
1. Processes: Multiple processes are competing for resources like CPU time,
memory, or input/output devices.
2. Resources: Resources can be either reusable (e.g., memory, CPU) or
consumable (e.g., files, database records).
4. Circular Wait: A deadlock occurs when a set of processes are each waiting
for a resource acquired by one of the other processes, forming a circular chain
of dependencies.
In this scenario, none of the processes can proceed because they are all waiting
for a resource held by another process. This forms a circular wait, leading to a
deadlock.
Assignment #4
8. Explain deadlock