Complete life cycle of the process - Linux
So Complete life cycle of the process can be circle as -
- Spawn
- Waiting
- Runnable
- Stopped
- Zombie
# ps -o pid, state, command
PID S Command
1661 S sudo su -
1662 S su -
1663 S -bash
1713 R ps -o pid, state, command
In the above output, you can see a column titled S shows the state of a process. We have here 3 sleeping and one running process. Let's dive into each state.
Process state: Running
The most healthy state of all. It indicates the process is active and serving its requests. The process is properly getting system resources(especially CPU) to perform its operations. Running process is a process which is being served by CPU currently. It can be identified by state flag R in ps or top output. The runnable state is when the process has got all the system resources to perform its operation except CPU. This means the process is ready to go once the CPU is free. Runnable processes are also flagged with state flag R.
Process state: Sleeping
The sleeping process is the one who waits for a resource to run. since it's on the waiting stand, it gives up CPU and goes to sleep mode. Once its required resource is free, it gets placed in the scheduler queue for CPU to execute. There are two types of sleep modes: interruptible and uninterruptible.
interruptible sleep mode:
In this mode, the process waits for a particular time slot or a specific event to occur. if those conditions occur, Then the process will come out of sleep mode. These processes are shown with state S in ps or top output.
uninterruptible sleep mode:
The process in this sleep mode gets its timeout value before going to sleep. Once the timeout sets off, it awakes. or it awakes when the waited-upon resource becomes available for it. it can be identified by state D
Process state: Stopped
The process ends or terminates when they receive a kill signal or they enter exit status. At this moment, the Process gives up all the occupied resources but does not release entry in the process table. Instead, it sends a signal about termination to its parent process. This helps the parent process to decide if a child is exited successfully or not. Once SIGCHKD received by the parent process, it takes action and releases child process entry in the process table.
Process state: Zombie
As explained above, while the existing process sends SIGCHLD to parent during the time between sending the signal to parent and then parent clearing out process slot in the process table, The process enters zombie mode. The process can stay in zombie mode if its parent died before it releases the child process's slot in process table.it can be identified with Z in outputs.

Comments
Post a Comment