Process Scheduling in Operating System
Subject: Computer Science Fundamentals · Language: Operating System · Level: intermediate · 9 min read
Understand process scheduling with ready queue, CPU scheduler, dispatcher, scheduling types, timing terms, and scheduling criteria.
Process scheduling is the method used by the operating system to decide which process should use the CPU next. In a computer system, many processes may be ready to run, but the CPU can execute only a limited number of processes at a time. On a single-core CPU, only one process runs at a particular instant. The operating system must choose a process from the ready processes and give it CPU time. This decision is called scheduling. Without scheduling, multiple programs could not run smoothly together, and the system could become unfair or unresponsive. For beginners, scheduling can be understood as queue management. Many processes are waiting for CPU, and the OS works like a manager who decides which process should go next based on some rule or algorithm.
Why Process Scheduling Is Needed
Process scheduling is needed because CPU is an important and limited resource. Many processes may want CPU at the same time. If the OS does not manage CPU properly, some processes may wait too long, some users may experience delay, and CPU time may be wasted. For example, suppose a browser, music player, code editor, and antivirus are running together. The OS must give CPU time to all of them in a balanced way. The music should not stop, the editor should respond to typing, and the browser should continue loading pages. Scheduling also helps improve CPU utilization. If one process is waiting for disk input-output, the CPU should not remain idle. The OS can give the CPU to another ready process during that waiting time.
Ready Queue
The ready queue is a queue of processes that are ready to run but are waiting for CPU. These processes already have memory and required resources, but they cannot execute until the scheduler selects them. When a process is created and ready for execution, it enters the ready queue. When the CPU becomes free or the OS decides to switch processes, the scheduler picks one process from the ready queue.
The ready queue does not always work like a simple first-in-first-out queue. Its order depends on the scheduling algorithm. In FCFS, arrival order matters. In priority scheduling, priority matters. In shortest job first, CPU burst time matters.
CPU Scheduler
The CPU scheduler is the part of the operating system that selects a process from the ready queue and allocates CPU to it. It is also called the short-term scheduler because it makes frequent decisions. The CPU scheduler runs many times during system operation. It may run when a process finishes, when a process waits for input-output, when a time quantum expires, or when a higher-priority process arrives. A good scheduler tries to keep the CPU busy, reduce waiting time, improve response time, and make the system fair. Different systems may prefer different scheduling goals.
Dispatcher
The dispatcher is responsible for giving control of the CPU to the process selected by the scheduler. The scheduler chooses the process, but the dispatcher performs the actual switch. The dispatcher saves the current process state if needed, loads the selected process state, switches to user mode, and starts or resumes execution of the selected process. The time taken by the dispatcher to stop one process and start another is called dispatch latency. Lower dispatch latency is better because context switching should not waste too much CPU time.
Long-Term, Short-Term, and Medium-Term Scheduler
The long-term scheduler decides which jobs are admitted into the system for processing. It controls the degree of multiprogramming, which means how many processes are allowed in memory at the same time. The short-term scheduler decides which ready process gets the CPU next. It runs very frequently and must be fast. Most CPU scheduling discussions mainly focus on the short-term scheduler.
The medium-term scheduler temporarily removes some processes from memory and brings them back later. This is called swapping. It helps control memory load and improves system performance when too many processes are active.
Preemptive Scheduling
In preemptive scheduling, the OS can take the CPU away from a running process before the process finishes. This may happen when a time quantum expires or when a higher-priority process arrives. Preemptive scheduling is useful for interactive systems because it prevents one process from holding the CPU for too long. It helps keep the system responsive for users.
For example, Round Robin scheduling is preemptive. Each process gets CPU for a fixed time slice. If it does not finish, it goes back to the ready queue and another process gets CPU. The disadvantage of preemptive scheduling is that it can cause more context switches. Too many context switches can reduce performance because switching itself takes time.
Non-Preemptive Scheduling
In non-preemptive scheduling, once a process gets the CPU, it keeps the CPU until it finishes or moves to the waiting state. The OS does not forcibly take the CPU away in the middle of execution. Non-preemptive scheduling is simpler and has less context-switching overhead. However, it can make short or interactive processes wait too long if a long process gets CPU first. For example, First Come First Serve is usually non-preemptive. The process that arrives first gets CPU first and keeps it until completion or blocking.
Important Scheduling Terms
Arrival time is the time at which a process enters the ready queue. If process P1 arrives at time 0 and P2 arrives at time 3, then P1 is available earlier than P2. Burst time is the amount of CPU time required by a process to complete its execution. It is also called CPU burst time. A process with burst time 5 needs 5 units of CPU time.
Completion time is the time at which a process finishes execution. If a process ends at time 12, its completion time is 12. Turnaround time is the total time taken by a process from arrival to completion. It is calculated as completion time minus arrival time.
Waiting time is the total time a process spends waiting in the ready queue. It does not include the time when the process is actually running on the CPU. Response time is the time from process arrival until it gets CPU for the first time. This is important in interactive systems because users care about how quickly the system gives the first response.
Scheduling Criteria
CPU utilization means how much of the time the CPU is busy doing useful work. A good system tries to keep CPU utilization high. Throughput means the number of processes completed in a given time. Higher throughput means the system is completing more work.
Turnaround time should be low because users want processes to complete quickly. Waiting time should also be low because long waiting makes the system inefficient. Response time should be low in interactive systems. When a user clicks, types, or opens an app, the system should respond quickly. Fairness means each process should get a reasonable chance to execute. A scheduling algorithm should avoid starvation, where a process waits indefinitely.
Scheduling and Context Switching
Scheduling often causes context switching. When the OS changes the CPU from one process to another, it saves the old process state and loads the new process state. Context switching is necessary for multitasking, but it has overhead. During a context switch, the CPU is not executing the actual user program. Therefore, scheduling should balance responsiveness with overhead.
Example Scenario
Suppose three processes are ready: P1 needs 10 units of CPU time, P2 needs 3 units, and P3 needs 2 units. If P1 runs first completely, P2 and P3 may wait for a long time. If a different algorithm gives shorter jobs priority, P2 and P3 may finish earlier. This example shows why scheduling algorithm choice matters. The same processes can have different waiting time and turnaround time depending on the scheduling rule used.
Summary
Process scheduling decides which ready process gets CPU next. It is needed to share CPU among multiple processes, improve CPU utilization, reduce waiting time, improve response time, and keep the system fair. The key concepts in this topic are ready queue, CPU scheduler, dispatcher, preemptive scheduling, non-preemptive scheduling, arrival time, burst time, completion time, turnaround time, waiting time, response time, throughput, and CPU utilization. These terms are required before learning CPU scheduling algorithms clearly.
Scheduling and User Experience
Scheduling directly affects how responsive a computer feels. If the scheduler gives too much CPU time to one heavy process, other applications may freeze or respond slowly. If the scheduler switches intelligently, users feel that many programs are running smoothly together. Interactive systems need quick response for user actions such as typing, clicking, scrolling, and opening windows. Batch systems may care more about completing many jobs efficiently. This is why scheduling goals can change depending on the system type.
Scheduling Decisions
The OS makes scheduling decisions when a process starts, waits for input-output, finishes input-output, uses its time slice, or terminates. At these moments, the scheduler decides which ready process should use the CPU next. A good scheduler balances fairness, response time, waiting time, throughput, and CPU utilization. No single policy is perfect for every situation, so operating systems use strategies suitable for their workload.
More Operating System Lessons
- Introduction to Operating System
- Types of Operating System
- Operating System Functions and Services
- System Calls in Operating System
- Process Management in Operating System
- CPU Scheduling Algorithms
- Threads and Multithreading in Operating System
- Process Synchronization in Operating System
- Deadlock in Operating System
- Memory Management in Operating System
- Virtual Memory in Operating System
- File System in Operating System