File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
0x05-processes_and_signals Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * File: 102-zombie.c
3
+ * Auth: Brennan D Baraban
4
+ */
5
+
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <sys/types.h>
9
+ #include <sys/wait.h>
10
+ #include <unistd.h>
11
+
12
+ /**
13
+ * infinite_while - Run an infinite while loop.
14
+ *
15
+ * Return: Always 0.
16
+ */
17
+ int infinite_while (void )
18
+ {
19
+ while (1 )
20
+ {
21
+ sleep (1 );
22
+ }
23
+ return (0 );
24
+ }
25
+
26
+ /**
27
+ * main - Creates five zombie processes.
28
+ *
29
+ * Return: Always 0.
30
+ */
31
+ int main (void )
32
+ {
33
+ pid_t pid ;
34
+ char count = 0 ;
35
+
36
+ while (count < 5 )
37
+ {
38
+ pid = fork ();
39
+ if (pid > 0 )
40
+ {
41
+ printf ("Zombie process created, PID: %d\n" , pid );
42
+ sleep (1 );
43
+ count ++ ;
44
+ }
45
+ else
46
+ exit (0 );
47
+ }
48
+
49
+ infinite_while ();
50
+
51
+ return (EXIT_SUCCESS );
52
+ }
You can’t perform that action at this time.
0 commit comments