Chapter 2 (English)
3. CPU Scheduling
CPU Scheduling in Operating Systems
CPU scheduling is a process used by the operating system to decide which task or process gets to use the CPU at a particular time. This is important because a CPU can only handle one task at a time, but there are usually many tasks that need to be processed. The following are different purposes of a CPU scheduling time.
- Maximize the CPU utilization
- Minimize the response and waiting time of the process.
What is the Need for a CPU Scheduling Algorithm?
CPU scheduling is the process of deciding which process will own the CPU to use while another process is suspended. The main function of CPU scheduling is to ensure that whenever the CPU remains idle, the OS has at least selected one of the processes available in the ready-to-use line.
Terminologies Used in CPU Scheduling
- Arrival Time: The time at which the process arrives in the ready queue.
- Completion Time: The time at which the process completes its execution.
- Burst Time: Time required by a process for CPU execution.
- Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time = Completion Time – Arrival Time
- Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time
Things to Take Care While Designing a CPU Scheduling Algorithm
Different CPU Scheduling algorithms have different structures and the choice of a particular algorithm depends on a variety of factors.
- CPU Utilization: The main purpose of any CPU algorithm is to keep the CPU as busy as possible. Theoretically, CPU usage can range from 0 to 100 but in a real-time system, it varies from 40 to 90 percent depending on the system load.
- Throughput: The average CPU performance is the number of processes performed and completed during each unit. This is called throughput. The output may vary depending on the length or duration of the processes.
- Turn Round Time: For a particular process, the important conditions are how long it takes to perform that process. The time elapsed from the time of process delivery to the time of completion is known as the conversion time. Conversion time is the amount of time spent waiting for memory access, waiting in line, using CPU and waiting for I/O.
- Waiting Time: The Scheduling algorithm does not affect the time required to complete the process once it has started performing. It only affects the waiting time of the process i.e. the time spent in the waiting process in the ready queue.
- Response Time: In a collaborative system, turn around time is not the best option. The process may produce something early and continue to computing the new results while the previous results are released to the user. Therefore another method is the time taken in the submission of the application process until the first response is issued. This measure is called response time.
Different Types of CPU Scheduling Algorithms
There are mainly two types of scheduling methods:
- Preemptive Scheduling: Preemptive scheduling is used when a process switches from running state to ready state or from the waiting state to the ready state.
- Non-Preemptive Scheduling: Non-Preemptive scheduling is used when a process terminates , or when a process switches from running state to waiting state.
CPU Scheduling Algorithms
Let us now learn about these CPU scheduling algorithms in operating systems one by one:
- FCFS - First Come, First Serve
- SJF - Shortest Job First
- SRTF - Shortest Remaining Time First
- Round Robin
- Priority Scheduling
- HRRN - Highest Response Ratio Next
- Multiple Queue Scheduling
- Multilevel Feedback Queue Scheduling
Comparison of CPU Scheduling Algorithms
Here is a brief comparison between different CPU scheduling algorithms:
| Algorithm | Allocation | Complexity | Average waiting time (AWT) | Preemption | Starvation | Performance |
|---|---|---|---|---|---|---|
| FCFS | According to the arrival time of the processes, the CPU is allocated. | Simple and easy to implement | Large. |
No |
No |
Slow performance |
| SJF | Based on the lowest CPU burst time (BT). | More complex than FCFS | Smaller than FCFS |
No |
Yes |
Minimum Average Waiting Time |
| SRTF | Same as SJF the allocation of the CPU is based on the lowest CPU burst time (BT). But it is preemptive. | More complex than FCFS | Depending on some measures e.g., arrival time, process size, etc |
Yes |
Yes |
The preference is given to the short jobs |
| RR | According to the order of the process arrives with fixed time quantum (TQ) | The complexity depends on Time Quantum size | Large as compared to SJF and Priority scheduling. |
Yes |
No |
Each process has given a fairly fixed time |
| Priority Pre-emptive | According to the priority. The bigger priority task executes first | This type is less complex | Smaller than FCFS |
Yes |
Yes |
Well performance but contain a starvation problem |
| Priority non-preemptive | According to the priority with monitoring the new incoming higher priority jobs | This type is less complex than Priority preemptive | Preemptive Smaller than FCFS |
No |
Yes |
Most beneficial with batch systems |
| MLQ | According to the process that resides in the bigger queue priority | More complex than the priority scheduling algorithms | Smaller than FCFS |
No |
Yes |
Good performance but contain a starvation problem |
| MFLQ | According to the process of a bigger priority queue. | It is the most Complex but its complexity rate depends on the TQ size | Smaller than all scheduling types in many cases |
No |
No |
Good performance |