Created
January 8, 2024 00:00
-
-
Save Abdurahman-hassan/18e9658c507fec14f7b1e136e1331888 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
/** | |
* infinite_while - Infinite loop | |
* | |
* Return: Always 0 | |
*/ | |
int infinite_while(void) | |
{ | |
while (1) | |
{ | |
sleep(1); | |
} | |
return (0); | |
} | |
/** | |
* main - Entry point | |
* | |
* Return: Always 0 | |
*/ | |
int main(void) | |
{ | |
pid_t pid; | |
int i; | |
for (i = 0; i < 5; i++) | |
{ | |
/* Create a child process */ | |
pid = fork(); | |
if (pid > 0) | |
{ | |
printf("Zombie process created, PID: %d\n", pid); | |
} | |
else if (pid == 0) | |
{ | |
/* Child process exits immediately to become a zombie */ | |
exit(0); | |
} | |
else | |
{ | |
perror("fork"); | |
return (1); | |
} | |
} | |
/* Keep the parent process running */ | |
infinite_while(); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment