SIGCHLD, SIG_IGN and zombie processes

From: Grzegorz Jablonski (gwj_at_mangled_w-s.pl)
Date: 09/27/03


Date: Sat, 27 Sep 2003 22:51:49 +0200

Hello all,

I have the following program:

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

int main ()
{
 int i, j;

 signal (SIGCHLD, SIG_IGN);
 printf ("server waiting\n");
 if (fork () == 0)
 {
  printf ("hello from child\n");
  sleep (1);
  printf ("goodbye from child\n");
  exit (0);
 }
 for (i = 0; i < 10000000; i++) j += i;
 sleep (300);
 exit (0);
}

I ignore SIGCHLD to prevent creation of the zombie processes.
This program works as intended, no zombie is created.
If I remove the dummy for loop, the zombie process appears.
Am I mising something, or is it a bug?
I use kernel 2.4.21 with glibc-2.3.1

Regards,
GWJ



Relevant Pages

  • Re: Can somebody help...
    ... a number of unsafe constructs and non-standard extensions. ... That value is too large to portably store in an int. ... This results in undefined behavior because you lied to printf about what ...
    (comp.lang.cpp)
  • Re: Is this correct..??
    ... long int i; ... Almost everthing is defined in assembler. ... Easily defeated by compiler optimisations. ... printf and that the first assignment to i is never used and decides to ...
    (comp.lang.c)
  • Semaphores Block when they Shouldnt and Dont when they Should
    ... took the votes (encoded in the first character of the transmitted mes- ... int socketAccess; ... write(voteSocket, voteBuffer, 2); ... {printf("Couldn't make a socket.\n"); ...
    (comp.unix.programmer)
  • RSA encrypt/decrypt c program
    ... Encrypt or Decrypt? ... int i,number; ... printf;} ... scanf; ...
    (comp.programming)
  • Counting Semaphore - semCCreate woes
    ... 'reset' the counting semaphore starTransfer. ... volatile int m_index = 0; ... printf; ... switch (bogus) { ...
    (comp.os.vxworks)