-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzombie.c
41 lines (37 loc) · 945 Bytes
/
zombie.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
int main()
{
int id;
printf("BEFORE FORK::\n");
printf("MAIN PROCESS ID::%d\n",getpid());
//printf("MAIN PROCESS PARENT'S ID::%d\n",getppid());
printf("BEFORE FORK\n");
id=fork();
if(id!=0)
{
printf("\nPARENT PROCESS IS RUNNING\n");
printf("PARENT ID::%d\n",getpid());
//printf("PARENT's PARENT ID::%d\n",getppid());
printf("PARENT IS SLEEPING\n");
sleep(10);
printf("\nPARENT WOKE UP!\n");
while(1)
{
//Infinite loop
}
exit(-1);
}
else
{
printf("\nCHILD PROCESS RUNNING\n");
printf("CHILD ID::%d\n",getpid());
printf("CHILD'S PARENT::%d\n",getppid());
printf("CHILD IS SLEEPING\n");
sleep(5);
printf("\nCHILD WOKE UP\n");
exit(0);
}
printf("\nAFTER FORK\n");
}