Os 2
Os 2
Sahiwal Campus
Assignment # 02
Submitted To:
Ms. Shaheen Kousar
.
Submitted By:
Ameer Hamza .
Registration No:
FA23-BSE-157 . .
BS (Software Engineering)
DEPARTMENT OF COMPUTER SCIENCE
Question 1:
Examine how preemptive and non-preemptive scheduling affects real-time operating
system performance. Analyze their pros and cons, considering response time, waiting time,
and CPU utilization.
Preemptive and non-preemptive scheduling are two different approaches to task management in
operating systems, particularly in real-time systems.
1. Preemptive Scheduling:
o Pros:
Better Response Time: Higher-priority tasks are executed immediately,
improving the response time.
Efficient CPU Utilization: The CPU is never idle if there are tasks
waiting, as it can switch to another task when necessary.
o Cons:
Increased Overhead: Frequent switching between tasks can lead to more
overhead in terms of time spent on context switching.
Complexity: Managing task priorities and frequent preemptions can make
the system more complex.
2. Non-preemptive Scheduling:
o Pros:
Less Overhead: Since tasks are not interrupted, the system does not need
to perform as many context switches.
Simplicity: The scheduling is simpler to implement as tasks are completed
in the order they start.
o Cons:
Poor Response Time: Higher-priority tasks may have to wait for lower-
priority tasks to finish, increasing their response time.
CPU Underutilization: If a long-running task is executing, the CPU may
not be efficiently utilized for urgent tasks.
In real-time systems, preemptive scheduling is often preferred as it ensures that urgent tasks meet
their deadlines. However, non-preemptive scheduling may be suitable in simpler systems or
when the overhead of context switching is too high.
Question 2:
Explain how context switching affects CPU performance and identify the key factors
contributing to its overhead.
Context switching occurs when the CPU switches from executing one task to another. It involves
saving the state of the current task and loading the state of the next task.
While context switching is necessary for multitasking, frequent switching or inefficient handling
of task states can negatively impact CPU performance.