| 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]
|
| 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.
|