SIGCHLD is not delivered

Andreas Steenpaß steenpass@mathematik.uni-kl.de
Thu Mar 28 13:31:00 GMT 2013


I have noticed that sometimes SIGCHLD is not delivered when a child
process exits. I can reproduce this behaviour reliably under the
following, very special circumstances:

* Immediately before calling 'exit(0);', the child process calls some
command 'system("...");'.
* SIGCHLD is blocked.
* A second thread within the main process waits for SIGCHLD
viasigwaitinfo().
* In this second thread, immediately before calling sigwaitinfo(), a
third thread is created. This happens almost simultaneously to
'system("..."); exit(0);' in the child process.

This might sound weird at first, but this happened to me in a use case.
Please check the test case below.The program should just print 'foo' and
exit immediately as it does under Linux. Under Cygwin, it hangs. The
second call of sigwaitinfo() in thread_function() does not return. The
SIGCHLD which should be emitted when the child process exits is not caught.

I use a recent snapshot:
$ uname -a
CYGWIN_NT-6.1-WOW64 zoppo 1.7.18s(0.263/5/3) 20130309 21:57:01 i686 Cygwin

Best regards,
Andreas


test case:
####################
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>   // compile with -lpthread

void *dummy_function(void *args)
{
}

void *thread_function(void *args)
{
  sigset_t sigmask;
  sigemptyset(&sigmask);
  sigaddset(&sigmask, SIGUSR1);
  sigaddset(&sigmask, SIGCHLD);

  pthread_t thread2;

  sigset_t sigusr1;
  sigemptyset(&sigusr1);
  sigaddset(&sigusr1, SIGUSR1);
  sigwaitinfo(&sigusr1, NULL);

  pthread_create(&thread2, NULL, dummy_function, NULL);
  sigwaitinfo(&sigmask, NULL);
  wait(NULL);
}

void main()
{
  sigset_t sigmask;
  sigemptyset(&sigmask);
  sigaddset(&sigmask, SIGUSR1);
  sigaddset(&sigmask, SIGCHLD);
  sigprocmask(SIG_BLOCK, &sigmask, NULL);

  pid_t pid = fork();
  if (pid == 0) {   // child process
    sigset_t sigusr1;
    sigemptyset(&sigusr1);
    sigaddset(&sigusr1, SIGUSR1);
    sigwaitinfo(&sigusr1, NULL);
    system("echo foo");
    exit(0);
  }

  pthread_t thread1;
  pthread_create(&thread1, NULL, thread_function, NULL);

  kill(pid, SIGUSR1);
  pthread_kill(thread1, SIGUSR1);

  pthread_join(thread1, NULL);
  exit(0);
}
####################


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list