Submitted by: Hina Ghani Class-ID: CU-2785-2022 Dated: 25th November, 2024 Department: Computer Science Part A: Theoretical Questions 1) Define process scheduling and explain its importance in operating systems. Process Scheduling: Process Scheduling refers to the mechanism by which an operating system decides the order in which processes are executed by the CPU. It involves managing the CPU's time and resources among multiple processes to ensure optimal system performance. Process scheduling aims to maximize CPU utilization, improve system responsiveness, and achieve fairness among all processes. Importance of Process Scheduling in Operating Systems: 1) Efficient CPU Utilization It ensures the CPU is always busy by allocating it to processes that are ready to execute, minimizing idle time. 2) Multitasking It allows multiple processes to run seemingly simultaneously by rapidly switching the CPU among them, providing the illusion of concurrent execution. 3) Improved System Performance It optimizes resource allocation to reduce response time for interactive processes and completion time for batch jobs. 4) Fairness It ensures that all processes get a fair share of CPU time and resources, preventing any single process from monopolizing the system. 5) Process Prioritization It enables prioritizing critical or high-priority processes over less important ones, ensuring timely execution of essential tasks. 2) Compare preemptive and non-preemptive scheduling. Provide two examples of each. Feature Preemptive Scheduling Non-Preemptive Scheduling Definition CPU can be taken away from a CPU is allocated to a process until it running process and given to completes or voluntarily releases it. another. Interrupts Allows interruption of a running Does not allow interruption; the process. process runs to completion Responsiveness More responsive as high- Less responsive to high-priority priority processes can preempt tasks. lower-priority ones. Overhead Higher due to context switching Lower as no context switching overhead. occurs during execution. Fairness Fairer as all processes get CPU Less fair if a long-running process time dynamically. monopolizes the CPU. Use cases Real-time systems, time-sharing Batch processing, simpler systems. systems.
Examples of Preemptive Scheduling
Round Robin (RR) Each process is assigned a fixed time slice (quantum). If a process does not finish within its time slice, it is preempted, and the CPU is assigned to the next process. Priority Scheduling (Preemptive) Processes with higher priority can preempt the currently running process with a lower priority.
Examples of Non-Preemptive Scheduling
First-Come, First-Served (FCFS) Processes are executed in the order they arrive, with no interruptions until a process finishes. Shortest Job Next (SJN) The process with the shortest execution time is selected and runs to completion before the next one starts. 3. Explain the following scheduling criteria with examples: 1. CPU Utilization 2. Throughput 3. Turnaround Time 4. Waiting Time 5. Response Time Scheduling Criteria in Operating Systems 1) CPU Utilization The percentage of time the CPU is actively executing processes rather than being idle. Importance: High CPU utilization ensures that the system resources are effectively used. Example: If the CPU is busy for 80 seconds out of 100, the CPU utilization is 80%. A well-optimized scheduler increases this value. 2) Throughput The number of processes completed per unit of time. Importance: High throughput indicates efficient process management and resource utilization. Example: If 5 processes are completed in 1 second, the throughput is 5 processes per second. Batch systems often aim for maximum throughput. 3) Turnaround Time The total time taken for a process to complete, from submission to the time it finishes execution. Formula: Turnaround Time = Completion Time − Arrival Time Example: A process arrives at time 0, starts execution at time 2, and finishes at time 10. Its turnaround time is 10 – 0 = 10. Shortest Job Next (SJN) reduces average turnaround time. 4) Waiting Time The total time a process spends in the ready queue waiting for CPU allocation. Formula: Waiting Time = Turnaround Time − Burst Time Example: If a process has a burst time of 5 seconds and a turnaround time of 10 seconds, its waiting time is 10 – 5 = 5. Round Robin scheduling often minimizes waiting time for interactive processes. 5) Response Time The time from process submission to the first response (i.e. the first time it starts executing). Importance: Critical in interactive systems, where quick feedback is needed for a good user experience. Example: A process is submitted at time 0 and starts executing at time 3. Its response time is 3−0=3. Short time quantum in Round Robin improve response time. Bonus Question Discuss the impact of choosing a small or large time quantum in Round Robin scheduling. What trade-offs does it introduce? Provide examples. Impact of Time Quantum in Round Robin Scheduling The time quantum in Round Robin (RR) scheduling defines the fixed time a process is allowed to run before being preempted. The choice of a small or large time quantum significantly impacts system performance, introducing trade-offs between responsiveness, throughput, and overhead. 1. Small Time Quantum Impact: High Responsiveness: Interactive or short processes receive quick attention, making the system appear more responsive. Increased Context Switching Overhead: Frequent preemptions lead to more context switches, consuming CPU time for managing processes instead of executing them. Lower Throughput: CPU spends significant time on context switching rather than completing processes. Example: Suppose the time quantum is 2 ms, and switching overhead is 1 ms. A process needing 5 ms will require 3 time slices and cause 2 context switches, increasing overall execution time. Trade-offs: Improves responsiveness for interactive tasks but reduces efficiency due to excessive context switching. 2. Large Time Quantum Impact: Reduced Context Switching Overhead: Fewer context switches lead to more efficient CPU utilization. Decreased Responsiveness: Interactive processes might experience delays, as they must wait longer before being served. Fairness Issues: Large processes may monopolize the CPU, impacting the performance of smaller or interactive processes. Example: If the time quantum is 10 ms, a process requiring 5 ms completes in one slice with no preemption, but an interactive process arriving during its execution waits longer, reducing system responsiveness. Trade-offs: Enhances throughput and CPU utilization but sacrifices fairness and responsiveness. Conclusion The choice of time quantum introduces a trade-off between: Responsiveness (favoring smaller quantum) Efficiency (favoring larger quantum)