-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzombie.c
More file actions
34 lines (29 loc) · 834 Bytes
/
Copy pathzombie.c
File metadata and controls
34 lines (29 loc) · 834 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t child_pid;
// Create a child process
child_pid = fork();
if (child_pid < 0) {
// Fork failed
perror("fork");
exit(EXIT_FAILURE);
} else if (child_pid == 0) {
// Child process
printf("Child process created with PID: %d\n", getpid());
// Sleep to make the child process a zombie
sleep(2);
printf("Child process exiting\n");
exit(EXIT_SUCCESS);
} else {
// Parent process
printf("Parent process with PID: %d\n", getpid());
// Sleep to make sure the child process becomes a zombie before parent exits
sleep(5);
printf("Parent process exiting\n");
exit(EXIT_SUCCESS);
}
return 0;
}