Processes States
In this lesson, you will learn about different states of a process and how a process changes from one state to another.
We'll cover the following
The three states of a process
Now that we have some idea of what a process is (though we will continue to refine this notion), and (roughly) how it is created, let us talk about the different states a process can be in at a given time. The notion that a process can be in one of these states arose in
• Running: In the running state, a process is running on a processor. This means it is executing instructions.
• Ready: In the ready state, a process is ready to run but for some reason, the OS has chosen not to run it at this given moment.
• Blocked: In the blocked state, a process has performed some kind of operation that makes it not ready to run until some other event takes place. A common example: when a process initiates an I/O request to a disk, it becomes blocked and thus some other process can use the processor.
Transitioning from one state to another
If we were to map these states to a graph, we would arrive at the diagram as shown below.
As you can see in the diagram, a process can be moved between the ready and running states at the discretion of the OS. Being moved from ready to running means the process has been scheduled; being moved from running to ready means the process has been descheduled. Once a process has become blocked (e.g., by initiating an I/O operation), the OS will keep it as such until some event occurs (e.g., I/O completion); at that point, the process moves to the ready state again (and potentially immediately to running again, if the OS so decides).
Let’s look at an example of how two processes might transition through some of these states. First, imagine two processes running, each of which only uses the CPU (they do no I/O). In this case, a trace of the state of each process might look like this:
In this next example, the first process issues an I/O after running for some time. At that point, the process is blocked, giving the other process a chance to run. The figure below shows a trace of this scenario:
More specifically, Process0 initiates an I/O and becomes blocked waiting for it to complete; processes become blocked, for example, when reading from a disk or waiting for a packet from a network. The OS recognizes Process0 is not using the CPU and starts running Process1. While Process1 is running, the I/O completes, moving Process0 back to ready. Finally, Process1 finishes, and Process0 runs and then is done.
Note that there are many decisions the OS must make, even in this simple example. First, the system had to decide to run Process1 while Process0 issued an I/O; doing so improves resource utilization by keeping the CPU busy. Second, the system decided not to switch back to Process0 when its I/O completed; it is not clear if this is a good decision or not. What do you think? These types of decisions are made by the OS scheduler, a topic we will discuss a few chapters in the future.
Get hands-on with 1400+ tech skills courses.