Process states and Transitions in a UNIX Process
Last Updated :
25 Jun, 2024
Process is an instance of a program in execution. A set of processes combined together make a complete program. There are two categories of processes in Unix, namely
- User processes : They are operated in user mode.
- Kernel processes : They are operated in kernel mode.
Process States
The lifetime of a process can be divided into a set of states, each with certain characteristics that describe the process. It is essential to understand the following states now:
1. The process is currently executing in user mode.
2. The process is currently executing in kernel mode.
3. The process is not executing, but it is ready to run as soon as the scheduler chooses it. Many processes may be in this state, and the scheduling algorithm determines which one will execute next.
4. The process is sleeping. A process puts itself to sleep when it can no longer
continue executing, such as when it is waiting for 1/0 to complete.
5.The process is ready to run, but the swapper(process 0) must swap the process into main memory before the kernel can schedule it to execute.
6.The process is sleeping, and the swapper has swapped the process to secondary storage to make room for other processes in main memory.
7. The process is returning from the kernel to user mode, but the kernel preempts it and does a context switch to schedule another process. The distinction between this state and state 3(“ready to run”) will be brought out shortly.
8. The process is newly created and is in a transition state; the process exists, but it is not ready to run, nor is it sleeping. This state is the start state for all processes except process 0.
9. The process executed the exit system call and is in the zombie state. The process no longer exists, but it leaves a record containing an exit code and some timing statistics for its parent process to collect. The zombie state i. the final state of a process.
Because a processor can execute only one process at a time, at most one process
may be in states 1 and 2. The two states correspond to the two modes of execution,
user and kernel.
The states that a Process enters in working from start till end are known as Process states. These are listed below as:
- Created -Process is newly created by system call, is not ready to run
- User running -Process is running in user mode which means it is a user process.
- Kernel Running -Indicates process is a kernel process running in kernel mode.
- Zombie- Process does not exist/ is terminated.
- Preempted- When process runs from kernel to user mode, it is said to be preempted.
- Ready to run in memory- It indicated that process has reached a state where it is ready to run in memory and is waiting for kernel to schedule it.
- Ready to run, swapped – Process is ready to run but no empty main memory is present
- Sleep, swapped- Process has been swapped to secondary storage and is at a blocked state.
- Asleep in memory- Process is in memory(not swapped to secondary storage) but is in blocked state.
The numbers indicate the steps that are followed.
Process Transitions
The working of Process is explained in following steps:
- User-running: Process is in user-running.
- Kernel-running: Process is allocated to kernel and hence, is in kernel mode.
- Ready to run in memory: Further, after processing in main memory process is rescheduled to the Kernel.i.e.The process is not executing but is ready to run as soon as the kernel schedules it.
- Asleep in memory: Process is sleeping but resides in main memory. It is waiting for the task to begin.
- Ready to run, swapped: Process is ready to run and be swapped by the processor into main memory, thereby allowing kernel to schedule it for execution.
- Sleep, Swapped: Process is in sleep state in secondary memory, making space for execution of other processes in main memory. It may resume once the task is fulfilled.
- Pre-empted: Kernel preempts an on-going process for allocation of another process, while the first process is moving from kernel to user mode.
- Created: Process is newly created but not running. This is the start state for all processes.
- Zombie: Process has been executed thoroughly and exit call has been enabled. The process, thereby, no longer exists. But, it stores a statistical record for the process. This is the final state of all processes.