This can program primarily test how advanced concurrent server programs write to avoid zombie processes?

Source: Internet
Author: User

#include <unistd.h>#include<stdio.h>#include<stdlib.h>#include<signal.h>intMainvoid)  {  //signal (SIGCHLD, sig_ign);   intI=0; printf ("i son/pa ppid pid fpid\n"); //Ppid refers to the parent process PID of the current process//PID refers to the PID of the current process,//fpid refers to the value that the fork returns to the current process    while(1) {Sleep (1); //The reason to join this time is because, easy to see the changes in the program, or can not see the changes, even the mouse can not understand! pid_t fpid=Fork (); if(fpid==0) {printf ("%d child%4d%4d%4d\n", I,getppid (), Getpid (), fpid); //return 0;//These two effects are the same! Exit0); }          }  return 0; } [[email protected] desktop]# gcc b.c[[email protected] desktop]#./A. outI son/PA ppid pid fpid0Child16980 16981    00Child16980 16982    00Child16980 16983    00Child16980 16985    00Child16980 16988    00Child16980 16990    00Child16980 16991    00Child16980 16993    00Child16980 16995    00Child16980 16996    0^C[[email protected] desktop]# [[email protected] desktop]# PS aux| Grep-w'Z' //have spawned a lot of zombie processes Root16981  0.0  0.0      0     0pts/2z+ -: -   0:xx[A. out] <defunct>Root16982  0.0  0.0      0     0pts/2z+ -: -   0:xx[A. out] <defunct>Root16983  0.0  0.0      0     0pts/2z+ -: -   0:xx[A. out] <defunct>Root16985  0.0  0.0      0     0pts/2z+ -: -   0:xx[A. out] <defunct>Root16987  0.0  0.0   4340   804pts/3S+ -: -   0:xxgrep-w z[[email protected] desktop]# when putting signal (SIGCHLD, sig_ign); This line of code adds the following output:[[email protected] desktop]# gcc B.c[[email protected] desktop]#./A. outI son/PA ppid pid fpid0Child17135 17136    00Child17135 17137    00Child17135 17139    00Child17135 17140    00Child17135 17141    00Child17135 17142    00Child17135 17145    00Child17135 17147    00Child17135 17150    00Child17135 17151    00Child17135 17152    0^C[[email protected] desktop]# //No zombie process generated [[email protected] desktop]# PS aux| Grep-w'Z'Root17144  0.0  0.0   4336   796pts/3S+ -: the   0:xxgrep-w z[[email protected] desktop]# PS aux| Grep-w'Z'Root17149  0.0  0.0   4336   792pts/3S+ -: the   0:xxgrep-w z[[email protected] desktop]#

This can program primarily test how advanced concurrent server programs write to avoid zombie processes?

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.