You are on page 1of 6

Name: Syed kashifullah shah

CMS: 21118
Assignment: Operating System
Submitted to: Sir Sharjeel Gillani
Zombie Process:
A zombie process or defunct process is a process
that has completed execution but still has an entry in the process table.

How Zombie processes are created:


When a process is created in UNIX using fork()
system call, the address space of the Parent process is replicated. If the
parent process calls wait() system call, then the execution of parent is
suspended until the child is terminated. At the termination of the child,
a ‘SIGCHLD’ signal is generated which is delivered to the parent by the
kernel. Parent, on receipt of ‘SIGCHLD’ reaps the status of the child
from the process table. Even though, the child is terminated, there is an
entry in the process table corresponding to the child where the status is
stored. When parent collects the status, this entry is deleted. Thus, all
the traces of the child process are removed from the system. If the
Parent decides not to wait for the child’s termination and it executes its
subsequent task, then at the termination of the child, the exit status is
not read. Hence, there remains an entry in the process table even after
the termination of the child.

Code Example:
#include<stdio.h>

#include<unistd.h>

#include<sys/wait.h>

#include<sys/types.h>

int main()
{
int i;
int pid = fork();

if (pid == 0)
{
for (i=0; i<20; i++)
printf("I am Child\n");
}
else
{
printf("I am Parent\n");
while(1);
}
}

Does zombies process used any resource or not:


Zombie processes aren't real processes at all.
They are just entries in the kernel process table. This is the only resource
they consume. They do not consume any CPU or RAM. The only danger
of having zombies, is running out of space in process table.

Advantage of Zombie process and to whom:


The operating system can't just discard the child
process; the operation of the parent process may be dependent upon
knowing the exit status or resource usage of the child. I.e. The parent
process might need to know that the child exited abnormally, or it
might be collecting CPU usage statistics for its children, etc. So, the only
choice is to save off that information and make it available to the
parent when it finally does call wait(). This information is what a
zombie process is and it's a critical part of how process management
works on Unix/Linux. Zombie processes allow the parent to be
guaranteed to be able to retrieve exit status, accounting information,
and process id for child processes, regardless of whether the parent
calls wait() before or after the child process exits. This is the main
advantage of zombie process to the system.

How Zombie Processes are terminated:

A zombie is already dead, so you cannot kill it. To clean up a zombie, it


must be waited on by its parent, so killing the parent should work to
eliminate the zombie. (After the parent dies, the zombie will be
inherited by init, which will wait on it and clear its entry in the
process table.) If your daemon is spawning children that become
zombies, you have a bug. Your daemon should notice when its children
die and wait on them to determine their exit state.(The kill command
is used to end this process).

Process States Transitions in UNIX


1. User-running: Process is in user-running.
2. Kernel-running: Process is allocated to kernel and hence, is in kernel mode.
3. 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.
4. Asleep in memory: Process is sleeping but resides in main memory. It is
waiting for the task to begin.
5. 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.
6. 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.
7. Pre-empted: Kernel preempts an on-going process for allocation of another
process, while the first process is moving from kernel to user mode.
8. Created: Process is newly created but not running. This is the start state for
all processes.
9. 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.

You might also like