Fork,defuct Zombie Sample

Source: Internet
Author: User

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.