-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path6aa_zombie.c
35 lines (35 loc) · 1 KB
/
6aa_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
/*program to inplement the zombie process*/
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
int main() {
pid_t my_pid, child_pid, parent_pid;
child_pid = fork();
if (child_pid < 0) {
printf("\nFork failed, exiting!!\n");
exit(1);
}
if (child_pid == 0) {
// This is the child process part
printf("\n[CHILD] This is the child process.\n");
my_pid = getpid();
parent_pid = getppid();
printf("[CHILD] My pid is %d\n", my_pid);
printf("[CHILD] My parent's pid is %d\n", parent_pid);
printf("[CHILD] Exiting\n");
exit(1);
} else {
// This is the parent process part
printf("\n[PARENT] This is the parent process\n");
my_pid = getpid();
parent_pid = getppid();
printf("[PARENT] My pid is %d\n", my_pid);
printf("[PARENT] My parent's pid is %d\n", parent_pid);
printf("[PARENT] Sleeping for 10 seconds\n");
sleep(10);
printf("\n[PARENT] Child process with pid = %d has ended, but still has an entry in theprocess table. \n", child_pid);
printf("[PARENT] It is therefore a Zombie process\n");
}
return 0;
}