[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::decc

Title:DECC
Notice:General DEC C discussions
Moderator:TLE::D_SMITHNTE
Created:Fri Nov 13 1992
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2212
Total number of notes:11045

961.0. "Why no SIGCHLD signal for parent when child exits on VMS" by UKARC1::WOOD_J (John Wood, @UCG, ISV Eng & Tech Support (UK)) Thu Oct 27 1994 17:42

T.RTitleUserPersonal
Name
DateLines
961.1SIGCHLD Problem?NNTPD::"[email protected]"[email protected]Mon May 19 1997 04:4257
I have same problem in signal program.
Programing Environment:
	Digital UNIX 3.2 & 4.0b
	DEC C
when child process exited, Parent process can't get all SIGCHLD signal from
child process.
At next following test program, Parent prcess get SIGCHLD signal 2 times.
How can Parent process get signal(SIGCHLD) every time when child process
exited ?

#include        <signal.h>

void
sigh( int n )
{
        int     cpid;

        signal(SIGCHLD, sigh);
        printf( "11111111---SIGH\n" );
        cpid=wait( (int *)0 );
        printf( "sigh function cpid = %d\n", cpid );
}

void
main()
{
        int             cpid=0;

        signal(SIGCHLD, sigh);
        if( (cpid = fork()) == 0 )
        {
                printf("fork1 ok\n");
                exit();
        }
        printf("1: cpid = %d \n", cpid);
        if( (cpid = fork()) == 0 )
        {
	      printf(fork2 ok\n"};
	      exit(); 
        }
        printf("2: cpid = %d \n", cpid);
        if( (cpid = fork()) == 0 )
        {
                printf("fork3 ok\n");
                exit();
        }
        printf("3: cpid = %d \n", cpid);

        sleep( 3 );

        while( 1 )
        {
                printf( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" );
                sleep( 2 );
        }
}
[Posted by WWW Notes gateway]
961.2Need to handle all terminated children at each signalWIBBIN::NOYCEPulling weeds, pickin&#039; stonesMon May 19 1997 09:169
This isn't really a C language question, but rather a UNIX operating-system
question.

I suspect the answer is that if several of your child processes terminate
at about the same time, you only get one signal.  Therefore, your handler
needs to contain a loop.  It should probably call waitpid() with the WNOHANG
option.

If this doesn't help, ask the question in TURRIS::DIGITAL_UNIX.