When you are going to manage processes with utilities like TOP, as I will show you later,
you will see process states.
So let's try to understand the different states that the process can be in.
When a new process is started, forked is how we call that, it is scheduled.
And after being scheduled, it will get a runnable state.
And let me tell you a little bit about fork.
Fork is one of the ways to start a process in Linux.
And forking means that a parent shell creates the new process.
Technically, the parent shell will clone itself, then it will remove its current code and replace
it with the process code, and that will make the process a child of the current parent
shell.
Parent-child relations in processes are pretty important.
So a process that has been forked this way will be in a runnable state, and the runnable
state will show as R. In this state, the process will be waiting in the queue to be scheduled.
And runnable processes will get a time slice, which allows them to get a running state in
either kernel space or user space, depending on the nature of the process.
Runnable processes can get preempted or rescheduled.
And in that case, they will return to a runnable state and wait in the queue for a new time
slice.
That's how preemptive multitasking on the Linux system is working.
They need to share CPU time slices on the CPU.
A runnable process can be stopped using Control-Z if it's a foreground job, and it will show
as Task Stopped or T. And after being stopped, it can receive another signal to resume and
return to a runnable state.
That's basically what we have just done in the job management demo.
Now when it is running, the process may have to wait.
And a process that is waiting is referred to as blocking.
Blocking state, however, is not an official state in the Linux kernel.
Waiting processes can have different flags.
They can have the flag Task Interruptible, which is S, which means that the process is
waiting for hardware requests and system resource access or a signal.
It can also be Task Uninterruptible, which means that the process is waiting but does
not respond to signals.
And Task Killable means that the process is waiting, but it may be killed.
And Task Report Idle is used for kernel threats, which makes that this process will not count
for the load average.
You will see all of these states while monitoring process state through top or other utilities.
Now processes have an exit state as well.
When a process exits, which happens when it's terminated, it will briefly enter the Exit
Zombie state or Z state.
This is where it signals the parent process that it exits.
And all resources except for the PID are released in that state.
So the only thing remaining when a process is in the Exit Zombie state is the PID.
And in the next state, the process will enter the Exit Dead state.
And in this state, it will be reaped, and all remaining processes are cleaned up.
When a process gets reaped, that's the final state of cleaning it up, the parent process
is calling the Wait system call to collect the exit status of the child process.
And then finally, it can be cleaned up.
Now in this process, something can go wrong, and then a process becomes a zombie.
In this procedure, a process can also become a zombie when it has completed its task, but
the parent process hasn't collected its execution status.
Zombies are already dead, so they can't and don't have to be killed.
And the most important disadvantage is that zombies occupy a PID.
And if you want to get rid of the zombie, the parent process must collect the child
execution status.
You could send the sick child's signal to the parent to ask the parent to reap the zombie.
Or you could kill the parent process, and when the parent is killed, the zombie becomes
an orphan and will be adopted by the inner process, and that allows you to do further
management of it.
That's interesting background information, but normally, and hopefully, you won't need
it too often.
In the next video, you'll learn how to get process information using PS.