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)
  • Re: is this declaration correct
    ... if your implementation defines printf with the ... int printf(const int *, ... ... int printf(const int * restrict, ... scope, storage duration, and type indicated by the declaration ...
    (comp.lang.c)
  • Re: K$R xrcise 1-13 (histogram)
    ... int main ... pos = OUT; ... printf(" "); ... K&R never write a C99 update to TCPL ...
    (comp.lang.c)