A zombie process is a process that terminates before the parent process has a chance to collect its exit status with wait or Waitpid.
The child is called the zombie process because the process ended, but still exists in the process table.
the memory and resources allocated to it after the child process exits are freed, but it retains a record in the kernel process table that the kernel retains until the parent process reclaims the child process's exit state.
when the process entries are too long in the process table, they affect performance, causing the creation process to fail, system crashes, and so on.
The fork or EXEC function creates a new process to collect the exiting state of a new process to prevent zombie processes (zombie process), the parent process should call Waitpid wait for the child process to terminate, or the parent process exits, and the zombie process is destroyed. in Code
when i = n there are n zombie processes, and their parent process IP is PID because the PID for the child process has been executed at the beginning of the exit (0) So even in the fork loop, the child process will not create a new subprocess.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
int main (void)
{
pid_t pid = fork ();
if (PID = = 0)
{
int i = 0;
for (i = 0; i<10; i++)
{
pid_t pid = fork ();
if (!pid)
{
exit (0);
}
}
Pause ();
}
else
exit (0);
return exit_success;
}