delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2013/03/28/09:31:48

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:content-type:content-transfer-encoding; q=dns; s=default; b=YOc
PiSSH87ByaE846sW7zdA4acgZavj5fmcNrNaJypXq0D7/XE/Zz4tKpnGKTllQue0
IPSUYx9a4T0RwYuWPfYVseGJG4oiFXl4Jj1LTEuUt4GY8bLC2UILyNUrMv+5G060
HlJvNyFnmw8s6D/7f88YIED/ZjRnue1+Fhs8Qo2s=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:content-type:content-transfer-encoding; s=default; bh=+9bp/VkVH
wV85f4kWMKPVh1vx/c=; b=bqV7FOeR676o5yH6FQAqGIZAbqdFsmYUtewFhpzgD
5GQXowuV6N7L2VTRiS3vJf4Jwbf9+O2ZDMKEQ08rie5hXIuRE2tU1d5ZLAqG/qA2
Ymn/MPq7SBtrBw3AHwi45DGojI8I1dKqeVGSvIrXXmgEm4wQTN1PaTAxo2K/hfw0
nM=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_NO,RP_MATCHES_RCVD autolearn=ham version=3.3.1
Message-ID: <5154460D.4090101@mathematik.uni-kl.de>
Date: Thu, 28 Mar 2013 14:30:53 +0100
From: =?ISO-8859-1?Q?Andreas_Steenpa=DF?= <steenpass AT mathematik DOT uni-kl DOT de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: SIGCHLD is not delivered

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019