delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/13/15:09:07

X-Spam-Check-By: sourceware.org
Message-ID: <20060313200844.66932.qmail@web54109.mail.yahoo.com>
Date: Mon, 13 Mar 2006 12:08:44 -0800 (PST)
From: REIVILOS <reivilos AT yahoo DOT com>
Subject: SIGCHLD problem
To: cygwin AT cygwin DOT com
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

Hi everyone,
I've got a problem: child processes are sent a SIGCHLD
but none of them fork!
[I am not asking anyone to debug my code, I just
want to know what's happening]

See the source:

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/types.h>

void sigchld_handler(){
	sigset_t mask, bak;
  int pid;
  
  sigemptyset( &mask );
  sigaddset( &mask, SIGCHLD );
  sigprocmask( SIG_BLOCK, &mask, &bak );	

  printf("\nhandler...: I am %d,",getpid()); 
  while((pid=waitpid( -1, 0, 0 ))>0)
	  printf("I catch %d \n", pid);

	printf("\n"); 
}

int main(){
	sigset_t mask, bak;
	struct sigaction a;
	int pid;
	int i;
	
	printf("father : %d\n", getpid());
	
	/* set up handler */		
  a.sa_handler = sigchld_handler;
  a.sa_flags = 0;
  sigemptyset( &a.sa_mask );
  sigaction( SIGCHLD, &a, NULL );
    
	/* block sigchld */
  sigemptyset( &mask );
  sigaddset( &mask, SIGCHLD );
  sigprocmask( SIG_BLOCK, &mask, &bak );	
	
	/* spawn 5 children */
	for(i = 0; i < 5; i++)
	{
	if((pid=fork())==0)
		exit(0);
	else
		printf("%d spawned : %d\n",getpid(), pid);
	
	sleep(1);
	}
		
  sleep(1);
  /* restore sigchld */
/*  sigprocmask( SIG_SETMASK, &bak, &mask );			*/
	return 0;
}

output on cygwin:
-----------------

father : 3028
3028 spawned : 2948
3028 spawned : 4056

handler...: I am 4056,
3028 spawned : 2272

handler...: I am 2272,
3028 spawned : 880

handler...: I am 880,
3028 spawned : 3976

handler...: I am 3976,


How come? I don't get this error on AIX.

Is it a bug?

Thanks.
Reivilos

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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

- Raw text -


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