OPERATING SYSTEM OS UNIT 2 CPU scheduling, preemptive scheduling, non-preemptive scheduling, multilevel feedback queue scheduling, process priority, scheduling criteria, preemptive vs non-preemptive scheduling, multiple queuing scheduling algorithm, long-term scheduler, short-term scheduler, medium-term scheduler, round robin scheduling, first come first served, shortest job first, priority scheduling, relationship between scheduling algorithms, process state diagram.


UNIVERSITY EXAM ASKED QUESTION OF OPERATING SYSTEM  - UNIT 2

1. What are the circumstances under which the CPU scheduling decision take place? What are the advantages of preemptive and non-preemptive scheduling?

CPU scheduling decisions occur under various circumstances, including when a process switches from the running state to the waiting state (due to I/O request or termination), when a process switches from the running state to the ready state (due to time quantum expiration in preemptive scheduling), and when a process switches from the waiting state to the ready state (due to I/O completion).

Advantages of preemptive and non-preemptive scheduling:

  • Preemptive Scheduling: Allows the operating system to interrupt a currently executing process in favor of a higher-priority process. This helps in ensuring fairness, responsiveness, and better utilization of resources.
  • Non-preemptive Scheduling: Ensures that a process continues to execute until it voluntarily relinquishes the CPU or blocks for I/O. While simpler to implement, it may lead to poor responsiveness in systems with long-running tasks or real-time requirements.

2. What is multilevel feedback queue scheduling? Explain in detail.

Multilevel feedback queue scheduling is a CPU scheduling algorithm that assigns processes to multiple queues based on their priority and provides different scheduling algorithms for each queue. Processes are initially placed in the highest priority queue. If a process uses too much CPU time, it is demoted to a lower-priority queue. Conversely, if a process waits too long, it is promoted to a higher-priority queue.

Each queue may use a different scheduling algorithm, such as round-robin or first-come, first-served. This approach allows the system to handle a mix of CPU-bound and I/O-bound processes effectively, providing fairness and responsiveness.

3. What is meant by process priority? What are different types of priorities? What role does priority play in process scheduling?

Process priority refers to the relative importance or urgency assigned to a process for CPU scheduling purposes. Different types of priorities include:

  • Static Priority: Assigned by the system administrator or programmer and remains constant throughout the process's lifetime.
  • Dynamic Priority: Adjusted dynamically based on process behavior, such as CPU usage, I/O operations, or waiting time.

Priority plays a crucial role in process scheduling by determining the order in which processes are allocated CPU time. Higher-priority processes are given preference over lower-priority ones, ensuring that critical tasks are executed promptly and efficiently.

4. List and describe the five scheduling criteria used in evaluating various scheduling policies.

  1. CPU Utilization: Measures the percentage of time the CPU is busy executing processes. Higher CPU utilization indicates better efficiency.
  2. Throughput: Refers to the total number of processes completed within a unit of time. Higher throughput implies better performance.
  3. Turnaround Time: Represents the total time taken to execute a process, including waiting time, execution time, and I/O time. Lower turnaround time indicates faster processing.
  4. Waiting Time: Measures the total time a process spends waiting in the ready queue before getting CPU time. Minimizing waiting time enhances system responsiveness.
  5. Response Time: Represents the time taken from when a request is submitted until the first response is produced. Lower response time leads to better interactive performance.

5. What relation holds between each pair of algorithms: i) Priority and SJF ii) RR and SJF iii) Priority and FCFS?

i) Priority and SJF: Priority scheduling can preemptive or non-preemptive. In preemptive priority scheduling, it behaves similarly to SJF, where the highest priority process currently in the ready queue is selected for execution. However, if two processes have the same priority, SJF will be applied to break the tie.

ii) RR and SJF: Round-robin (RR) scheduling and Shortest Job First (SJF) scheduling are different algorithms. RR is a preemptive scheduling algorithm where each process is assigned a fixed time slice, while SJF selects the process with the shortest burst time for execution. RR ensures fairness and responsiveness, whereas SJF prioritizes shorter jobs for faster completion.

iii) Priority and FCFS: Priority scheduling and First-Come, First-Served (FCFS) scheduling are different algorithms. Priority scheduling selects processes based on their priority level, while FCFS executes processes based on their arrival order. Priority scheduling allows for the execution of high-priority tasks first, regardless of arrival time, while FCFS follows a strict FIFO order.

6. Differentiate between preemptive and non-preemptive scheduling algorithm and also explain multiple queuing scheduling algorithm.

Preemptive Scheduling: In preemptive scheduling, the operating system can interrupt a currently executing process to allocate the CPU to another process with a higher priority. This allows for better responsiveness and ensures that critical tasks can be executed promptly.

Non-preemptive Scheduling: Non-preemptive scheduling does not allow the operating system to interrupt a running process. The CPU is allocated to a process until it voluntarily relinquishes the CPU or blocks for I/O. While simpler to implement, non-preemptive scheduling may lead to poor responsiveness in systems with time-sensitive tasks.

Multiple Queuing Scheduling Algorithm: This scheduling algorithm involves maintaining multiple ready queues, each with its own scheduling algorithm and priority level. Processes are placed in the appropriate queue based on their characteristics, such as priority, CPU burst time, or I/O requirements. The operating system selects a queue to execute processes from based on predefined criteria, such as system load or process priority.

7. Differentiate between preemptive and non-preemptive scheduling.

Preemptive Scheduling: Allows the operating system to interrupt a currently executing process to allocate the CPU to another process with a higher priority. This ensures fairness, responsiveness, and efficient resource utilization.

Non-preemptive Scheduling: Does not allow the operating system to interrupt a running process. The CPU is allocated to a process until it voluntarily relinquishes the CPU or blocks for I/O. While simpler to implement, it may lead to poor responsiveness in systems with time-sensitive tasks.

8. Describe five scheduling criteria used in evaluating various scheduling policies?

The five scheduling criteria used in evaluating various scheduling policies are:

  1. CPU Utilization
  2. Throughput
  3. Turnaround Time
  4. Waiting Time
  5. Response Time

Each criterion measures a different aspect of scheduler performance and helps in selecting the most appropriate scheduling policy based on system requirements.

9. What are schedulers, Explain different types of schedulers with the help of a process state diagram?

Schedulers: Schedulers are components of the operating system responsible for selecting processes from the ready queue and allocating CPU resources to them. They play a crucial role in determining the order in which processes are executed and ensuring efficient utilization of system resources.

Types of Schedulers:

  • Long-Term Scheduler (Job Scheduler): Selects processes from the pool of new processes and loads them into memory for execution. It determines which processes will be admitted to the system and helps in maintaining an appropriate mix of I/O-bound and CPU-bound processes.
  • Short-Term Scheduler (CPU Scheduler): Selects processes from the ready queue and allocates CPU time to them. It makes frequent scheduling decisions to ensure fair access to the CPU and optimize system responsiveness.
  • Medium-Term Scheduler: Responsible for managing the degree of multiprogramming in the system. It may decide to swap out processes from main memory to secondary storage to improve overall system performance and resource utilization.

A process state diagram illustrates the different states a process can transition through during its lifetime, including new, ready, running, waiting, and terminated. Schedulers play a critical role in managing these transitions and ensuring efficient process execution.

1. Round Robin Scheduling

Process: P1, P2, P3, P4
Burst Time: 45, 12, 58, 32
Time Quantum: 15

Average Waiting Time: 21.75 milliseconds

Average Turnaround Time: 52 milliseconds

2. Gantt Chart for FCFS and SJF Scheduling

FCFS Scheduling:

P1 [0-10] -> P2 [10-11] -> P3 [11-13] -> P4 [13-14] -> P5 [14-19]

Average Waiting Time: 6.4 milliseconds

Average Turnaround Time: 11.8 milliseconds

SJF Scheduling:

P1 [0-10] -> P4 [10-11] -> P3 [11-13] -> P2 [13-14] -> P5 [14-19]

Average Waiting Time: 4 milliseconds

Average Turnaround Time: 9 milliseconds

Efficiency: SJF is more efficient as it reduces waiting time and turnaround time compared to FCFS.

3. Process Execution using Different Scheduling Algorithms

First Come First Served (FCFS):

A [0-4] -> B [4-11] -> C [11-13] -> D [13-15]

Shortest Job First (SJF):

A [0-4] -> C [4-6] -> D [6-8] -> B [8-15]

Shortest Remaining Time First (SRTF):

A [0-4] -> C [4-6] -> D [6-8] -> B [8-15]

Round Robin (Quantum = 2):

A [0-2] -> B [2-4] -> C [4-6] -> D [6-8] -> A [8-10] -> B [10-11] -> A [11-13] -> C [13-15]

Waiting Time & Turnaround Time calculations for each process...

4. Process Execution using Different Scheduling Algorithms

First Come First Served (FCFS):

P1 [10-13] -> P2 [13-14] -> P3 [14-17] -> P4 [17-21] -> P5 [21-23]

Shortest Job First (SJF):

P2 [1-2] -> P3 [2-4] -> P1 [4-7] -> P5 [7-12] -> P4 [12-13]

Priority Scheduling:

P2 [1-2] -> P3 [2-4] -> P4 [4-5] -> P5 [5-7] -> P1 [7-17]

Round Robin (Quantum = 1ms):

P2 [1-2] -> P3 [2-3] -> P4 [3-4] -> P3 [4-5] -> P5 [5-6] -> P1 [6-7] -> P1 [7-8] -> P1 [8-9] -> P1 [9-10] -> P1 [10-11] -> P1 [11-13] -> P4 [13-14] -> P5 [14-15]

Waiting Time & Turnaround Time calculations for each process...

First Come First Served (FCFS):

P4[0-1] -> P0 [1-4] -> P2 [4-10] -> P3 [10-15] -> P1 [15-21]

Average Waiting Time: 6.6 milliseconds

Average Turnaround Time: 10.4 milliseconds

SJF-Preemption Algorithm:

P0 [0-3] -> P4 [3-5] -> P3 [5-10] -> P2 [10-12] -> P1 [12-18]

Average Waiting Time: 2 milliseconds

Average Turnaround Time: 6.2 milliseconds

Round Robin Algorithm (Q = 1):

P4 [0-1] -> P0 [1-2] -> P4 [2-3] -> P3 [3-4] -> P4 [4-5] -> P2 [5-6] -> P3 [6-7] -> P1 [7-8] -> P3 [8-9] -> P1 [9-10] -> P3 [10-11] -> P1 [11-12] -> P3 [12-13] -> P1 [13-14] -> P3 [14-15] -> P1 [15-16] -> P3 [16-17] -> P1 [17-18]

Average Waiting Time: 5.6 milliseconds

Average Turnaround Time: 9.8 milliseconds

FOR QUESTION

FOR ANSWER