What is Zombie process and How to create zombie process in Linux ?

Zombie process is the process which died immediately and whose parent didn’t cared to handled the status of child death. When a child process exits, it is not immediately cleared off the process table. Instead, a signal is sent to its parent process, which needs to acknowledge it’s child’s death, and only then the child process is completely removed from the system. If a parent is not written by taking care of handling acknowledgement from child, the child becomes zombie.

Such process’s continues to run in

<defunct>

state till the parent is exited completely.

 vim create_zombie.c 
int main(int argc, char **argv) { pid_t child_pid; int child_status; child_pid = fork(); switch (child_pid) { case -1: printf("error: we can use perror\n"); perror("fork"); exit(1); case 0: printf("child is getting dead immediately\n"); exit(0); default: printf("parent process continuing to execute, but not cared of child is dead or alive\n"); sleep (180); } return 0;
}

you can run below program as,

 gcc -o our_zombie_child create_zombie.c ./our_zombie_child

This program makes parent goes sleep for 180 sec, meantime child has already died, but parent process doesn’t handles the child’s death since it was already in sleep ( normally this child death report needs to handled using signal in parent process )

READ  Difference between Thread and Process

so now, you can open another terminal and type

 $ ps -ax | grep defunct 5208 pts/1 Z+ 0:00 [our_zombie_chil] defunct

where “ps” command showed, child process which we created became zombie. [ as indicated by defunct ]

Leave a Reply

Your email address will not be published. Required fields are marked *