Mail Archives: cygwin/2006/03/13/15:09:07
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 -