Process Scheduling: Operating System
Have you ever wondered how your computer juggles multiple tasks simultaneously? To know that, you must read this blog on process scheduling in operating system!
Best-suited Operating Systems courses for you
Learn Operating Systems with these high-rated online courses
What is Process Scheduling?
Process scheduling is allocating resources to tasks so that the tasks can be completed in an efficient and timely manner.
There are a few different types of schedulers:
- Batch Operating system
- Time-sharing Operating system
- Multiprogramming Operating system
- Multiprocessing Operating system, etc.
We will cover these operating systems in the next blog. Stay tuned!!!
Objectives of Process Scheduling
- Optimize the use of resources present.
- Keep the CPU busy and have maximum utilization of the CPU.
- Minimum response time for executing a process means the shortest possible time for process execution.
Explore Operating System Online Courses & Certifications
Process Queues
There are multiple stages through which a process goes before its execution. A separate queue is maintained for all states.
These process scheduling queues are:
1. Job queue: All the processes stay here in this job before their execution. Now, processes are picked up and put in the READY queue.
2. Ready queue: The processes waiting to get executed are put in the READY queue. They remain here until they are picked up one by one for execution.
3. Device queue: If the process is blocked during execution due to the unavailability of an I/O device, it goes to the Device queue.
Types of Schedulers
A scheduler is a software that helps schedule the processes in an operating system. It helps to keep all computer resources busy and allows multiple users to share system resources effectively. Let’s go through different schedulers in an operating system.
1. Long-term schedulers
The processes that are created are in the NEW state. The programs are admitted to the RAM for execution. So before execution, the processes are put in the READY queue. So, do they get into the ready queue themselves? Here comes the role of long-term schedulers(LTS). It is also called a job scheduler. These schedulers select processes from secondary memory and put them into the ready queue.LTS runs less frequently. The main aim of LTS is to maintain the degree of multiprogramming. Multiprogramming means executing multiple programs by a single processor. But not all processes simultaneously. It means if one process is not executing for some reason, then another process will get a chance to get executed. An optimal level of multiprogramming means
The average rate of process = average departure rate of processes getting executed and leaving the system.
2. Short-term schedulers
It is also called a CPU scheduler. When the processes are in the ready queue, they are prepared to get executed. So the short-term schedulers select one process from the ready queue, put it in the running queue, and allocate a processor(CPU) to it. They are also known as the dispatcher who decides which process will execute next. They are faster than long-term schedulers. The performance of the system depends on the choice of Short-term schedulers. If it selects the processes having high burst time, then, in that case, other processes in the waiting queue will keep on waiting in the ready queue. This situation is called starvation.
3. Medium-term schedulers
When the process is assigned CPU and the program execution starts, program execution is sometimes suspended. The reason could be an I/O request or some high-priority process. In this case, suspended processes cannot make any progress towards completion. So the process has to be removed from the memory and make space for other processes. The suspended process is moved back to the secondary storage. For example-Suppose, process 1 was executing, but it got suspended for some reason, so process 1 is swapped out, and process 2 is swapped in. This means swapping is taking place here. For doing swapping, we have a medium-term scheduler.
Comparison of OS Schedulers
Criteria | Long-Term Scheduler(LTS)/job scheduler | Short-Term Scheduler(STS)/ CPU scheduler | Medium-Term Scheduler(MTS)/swapping scheduler |
Type of process | It chooses a combination of CPU-bound and I/O-bound processes. | It chooses the process to be executed. | It chooses the process which needs to be swapped in/out. |
Speed | Have a slow speed than a short-term scheduler as different processes are to be selected. | Fastest Speed as one process is selected at one time. | It has speed is between the other two |
Frequency of execution | It executes much less frequently. As its job is to load processes in the ready queue only. | The short-term scheduler executes more frequently, at least once every 100 milliseconds. | Frequency is in between both |
Degree of multi-programming | It controls the number of processes in the memory means DOM(degree of multiprogramming) | Ensures less DOM(degree of multiprogramming) | It reduces DOM(degree of multiprogramming) |
Working | It selects a process from a pool of processes and loads it into the READY queue. | Selects a process in the READY state and put it in the RUNNING state for execution | If some interrupt comes, it swaps the process out and swaps the process back for execution. |
CPU and I/O bound processes
While executing a process needs CPU and I/O devices both. There is a need to have a balanced mix of CPU and I/O bound.
1. CPU Bound Process
These processes execute at the speed of the computer processor or central processor unit and involve more CPU usage. For example, the processes involving complex calculations are CPU-bound processes.
Note-These processes involve I/O devices also, but CPU involvement is more.
2. I/O Bound Process
These processes are executed at the speed of the I/O subsystem and involve more usage of I/O devices than the CPU. I/O bound process spends a significant amount of time waiting for input or output from a peripheral device. For example- Reading/writing to a disk
Since these processes can’t proceed until the requested data is available, they can often be delayed by other processes that are running on the system. This can cause problems with CPU utilization and lead to overall system instability.
To optimize system performance, it’s crucial to identify and allocate resources to I/O-bound processes. This can be done using a variety of schedules, such as the FCFS, SJF, and Round Robin schedulers.
Context Switching
Context switching is the process of temporarily taking control of a computer from its current task and then switching to a different task. This process allows users to perform different tasks on the computer simultaneously. It is one of the most important aspects of operating systems, as it will enable users to access various applications and files easily.
Context switching has advantages and disadvantages.
Advantages
- Context switching allows users to quickly switch between tasks, which can be helpful when working on complex tasks.
- Context switching can also be used to keep users updated on various events in the operating system.
- It is so fast that it gives an illusion of execution of multiple processes at the same time.
Disadvantages
- Context switching can be time-consuming and require users to learn new techniques.
- CPU remains idle and does not do any useful work.
Conclusion
This article covered process queues in the operating systems, types of schedulers, and their comparison. If you liked the article, please share it with your friends.
FAQs
What is a process control block (PCB)?
A process control block (PCB) is a data structure maintained by the operating system for each process. It contains information about the process, such as its process ID, program counter, CPU registers, memory allocation, file descriptors, scheduling information, and other relevant details needed for process management and context switching.
Can process scheduling algorithms be dynamically adjusted during runtime?
Yes, process scheduling algorithms can be dynamically adjusted during runtime based on changing system conditions or priorities. For example, the priority of a process can be adjusted dynamically based on its behavior or resource requirements.
What is the difference between preemptive and non-preemptive scheduling?
Preemptive scheduling allows the operating system to interrupt a running process and allocate the CPU to another process based on priority or time quantum. Non-preemptive scheduling, on the other hand, allows a process to continue running until it voluntarily releases the CPU. Preemptive scheduling provides better responsiveness and avoids blocking higher-priority processes for an extended period.
Anshuman Singh is an accomplished content writer with over three years of experience specializing in cybersecurity, cloud computing, networking, and software testing. Known for his clear, concise, and informative wr... Read Full Bio