8 Demonstrating Zombie State in C

Program:

#include<stdio.h>

void main()
{
    int cpid = fork();

    if(cpid >0)
    {
        printf("\n\n Parent is Running:\n");
        printf("\n\n Parent PID is %d ",getpid());
        printf("\n Parent is Going to Sleep:\n\n");
        sleep(10);
        printf("\n\n Parent Wake's Up:\n");
        wait(NULL);
        printf("\n Parent is Exiting\n");
        
    }
    else if(cpid == 0)
    {
        printf("\n\n Child is Running:\n");
        printf("\n\n Child pid is %d and Parent Pid is %d\n",getpid(),getppid());
        printf("\n Child is Going to Sleep:\n\n");
        sleep(1);
        printf("\n\n Child Wake's Up:\n");
        printf("\nChild is Exiting\n");
    }
}


Output:

1) Before Running:


2) Child Process in Zombie State Created



3) Parent Exit




Previous
Next Post »