#define __use_largefile64
#define _largefile64_source
#ifndef _gnu_source
#define _gnu_source
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <pthread.h>
#include <sys/wait.h>
#include <signal.h>
int main (int argc, char *argv[])
{
int flag = 1;
pid_t pid;
PID = fork ();
while (1)
{
if (1 = = flag)
{
Flag = 0;
if (PID = = 0)
{
printf ("In Child,pid:%d,ppid:%d,then exit child...\n", Getpid (), Getppid ());
Exit (0);
}
Else
{
printf ("In Parent,pid:%d,ppid:%d,then waitpid...\n", Getpid (), Getppid ());
#if 1
/*when the 3rd para is 0 wuntraced wstopped wcontinued,child process won ' t defunct*/
Waitpid (PID, NULL, 0);
#else
/*when the 3rd para is Wnohang wexited wnowait,child process would defunct*/
Waitpid (PID, NULL, Wnohang);
#endif
}
}
}
}
Fork,defuct Zombie Sample