Last updated
Last updated
A process in an operating system can be in one of several states¹:
New (Create): The process is about to be created but not yet created. It is the program that is present in secondary memory that will be picked up by the OS to create the process¹.
Ready: After the creation of a process, the process enters the ready state i.e., the process is loaded into the main memory. The process here is ready to run and is waiting to get the CPU time for its execution¹.
Run: The process is chosen from the ready queue by the CPU for execution and the instructions within the process are executed by any one of the available CPU cores¹.
Blocked or Wait: Whenever the process requests access to I/O or needs input from the user or needs access to a critical region (the lock for which is already acquired) it enters the blocked or waits for state¹.
Terminated or Completed: The process is killed and its Process Control Block (PCB) is deleted. The resources allocated to the process will be released or deallocated¹.
Extra :
Suspend Ready: A process that was initially in the ready state but was swapped out of main memory and placed onto external storage by the scheduler is said to be in suspend ready state¹.
Suspend wait or suspend blocked: Similar to suspend ready but uses the process which was performing I/O operation and lack of main memory caused them to move to secondary memory¹.
A process can move between different states based on its execution status and resource availability¹. For example, a new process moves to the ready state when it's created and resources are allocated to it. When the CPU becomes available, it moves from ready to running state¹. If a running process requests I/O, it moves from running to waiting state¹. Once I/O operation is completed, it moves back to ready state¹. When a process completes its execution or when it's explicitly killed, it moves to terminated state¹.
There are three main types of queues used in process scheduling¹³⁴:
Job Queue: This queue stores all the processes in the system¹. It ensures that processes stay in the system³.
Ready Queue: This queue stores a set of all processes residing in the main memory, ready and waiting for execution¹³. The ready queue stores any new process³.
Wait Queue : Waiting Queue or Blocked Queue, is where processes that are waiting for a certain event or condition (like I/O operation completion) are kept. When a process issues an I/O request, the operating system places it in the I/O queue. These processes are in a blocked or waiting state and cannot continue their execution until the event for which they are waiting occurs. Once the event occurs, these processes are moved back to the Ready Queue.
Extra :
Device Queue: This queue consists of the processes blocked due to the unavailability of an I/O device¹³. It is a process that is blocked because of the absence of an I/O device⁴.
These queues are maintained by the operating system and play a crucial role in managing processes and their execution¹.
Schedulers and dispatchers are key components of an operating system.
Schedulers are special system software that handle process scheduling in various ways. Their main task is to select the jobs to be submitted into the system and to decide which process to run. There are three types of schedulers¹:
Long-term (job) scheduler: Decides how many processes will stay in the ready queue, thus determining the degree of multi-programming of the system.
Medium-term scheduler: Handles the shifting of a process from the running queue to the blocked queue when an I/O operation is required, and vice versa.
Short-term (CPU) scheduler: Selects a single process for execution among all of the processes in main memory.
A dispatcher is a special program that comes into play after the scheduler. When the scheduler completes its job of selecting a process, it is the dispatcher which takes that process to the desired state/queue. The dispatcher gives a process control over the CPU after it has been selected by the short-term scheduler. This function involves:
Switching context
Switching to user mode
Jumping to the proper location in the user program to restart that program
In simple terms, the scheduler selects a process from various processes based on a scheduling algorithm, and once a process has been selected, the dispatcher moves that process from the ready queue into the running state.