The previous Process Control 2, describes the zombie process, and the solution of the two kinds of 4. Add two more below.
How to resolve:
3: Ignore SIGCHLD signal
Parent process settings Ignore SIGCHLD signal, child process end automatically frees process table resource
Ignore SIGCHLD signal:
Signal (SIGCHLD, sig_ign)
4: Capture SIGCHLD Signal
The parent process captures the SIGCHLD signal and executes the wait () in the Capture function code
Handling SIGCHLD Signals:
void Pfun (int nsignal)
Signal (Sigchil, Pfun)
Zombie Process:
void Testzomb ()
{
pid_t pid=fork ();
if (pid==0)
{
printf ("This is a child:%d\n", getpid ());
_exit (0);
}
Else
{
printf ("This is a parent:%d\n", getpid ());
while (1);
}
}
Rowe 3440 3110 23:04 pts/0 00:00:08./main
Rowe 3441 3440 0 23:04 pts/0 00:00:00 [main] <defunct>
The <defunct> description is a zombie process and cannot be terminated with the kill command, nor can it be manipulated.
Ignore SIGCHLD signal mode:
void Testzomb ()
{
pid_t pid=fork ();
if (pid==0)
{
printf ("This is a child:%d\n", getpid ());
_exit (0);
}
Else
{
Parent process ignores SIGCHLD
Signal (sigchld,sig_ign);
printf ("This is a parent:%d\n", getpid ());
while (1);
}
}
Capture SIGCHLD Signal mode:
void func (int sig)
{
printf ("Receive signal:%s[%d]\n", Strsignal (SIG), SIG);
Wait (NULL);
}
void Testzomb ()
{
pid_t pid=fork ();
if (pid==0)
{
printf ("This is a child:%d\n", getpid ());
_exit (0);
}
Else
{
The parent process handles the SIGCHLD
Signal (SIGCHLD,FUNC);
printf ("This is a parent:%d\n", getpid ());
while (1);
}
}
After wait ends, the process Resource table is freed by Init.
14 Zombie Process Mode 3 4 supplement