Skip to content

Instantly share code, notes, and snippets.

@Abdurahman-hassan
Created January 8, 2024 00:00
Show Gist options
  • Save Abdurahman-hassan/18e9658c507fec14f7b1e136e1331888 to your computer and use it in GitHub Desktop.
Save Abdurahman-hassan/18e9658c507fec14f7b1e136e1331888 to your computer and use it in GitHub Desktop.
#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