Skip to content

Commit ef1e0c7

Browse files
committed
ju
1 parent a4e3dbb commit ef1e0c7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

0 commit comments

Comments
 (0)