Process Lifecycle
- after process is scheduled it will get a time slice
Runnable process states
When a new process is started (forked) it is scheduled and after being scheduled, it will get a runnable state (R).
« In this state it is waiting in the queue to be scheduled Runnable processes will get a time slice, which allows them to get a running state, in either kernel space or user space Runnable processes can get preempted or rescheduled
- In that case, they will return to a runnable state and wait in the
queue for a new time slice
A runnable process can be stopped (ctrl-z) and will show as TASK_STOPPED (T), and after being stopped it can receive another signal to resume and return to a runnable state
Waiting
- While running, the process may have to wait
- This is also referred to as “blocking” state, but “blocking” is not an official state in the Linux kernel
- Waiting processes can have different flags
- TASK_INTERRUPTIBLE (S): the process is waiting for hardware request, system resource access or a signal
- TASK_UNINTERRUPTIBLE (D): the process is waiting but does not respond to signals
- TASK_KILLABLE (K) :the process is waiting but may be killed
- TASK_REPORT_IDLE (I): Used for kernel threads, this process will not count for the load average
Exit
What happens when a process exits?
- When a process exits, it will briefly enter the EXIT_ZOMBIE (Z) state. This is where it signals the parent process that it exits and all resources except for the PID are released
- In the next stage the process will enter the EXIT_DEAD (X) state. In this state it will be reaped and all remaining processes are cleaned up