Signal Handling

Hi folks
I'm trying to write a signal handler (in c on HPUX) that will catch the child process launched by execl when it's finished so that I can check a compliance file.
The signal handler appears to catch the child process terminating however when the signal handler completes the parent process crashes and restarts.

Please can anyone give me any advice as to what I'm doing wrong.

// main
signal(SIGCHLD, TerminateChild);

int pid = fork();
// if pid O.K
execl(params); // launch a seperate Java process

// end main

void TerminateChild(int sig)
{
int pid, status;
pid = waitpid(-1, &status, WNOHANG);

// Check a file for a compliance
// send IPC message    
signal\(SIGCHLD, TerminateChild\);

}

Is there a reason you cannot call waitpid() -- or wait()?

Signals arrive asynchronously, so you parent process' code could be in any state when the signal arrives..... but if you do stuff, then call wait() you're at a known point.

Hi
I have used the following call to waitpid in my TerminateChild handler:
pid = waitpid(-1, &status, WNOHANG);

Have I used it incorrectly?

I don't think that jim means that you are using waitpid incorrectly. What he means is that your program might be at *any* stage when SIGCHLD is received. But instead, if you carry out some execution, and then wait at a particular point in the code, you know what point you have stopped and 'waitpid'ed for the child.

And about that waitpid, is it necessary to specify WNOHANG? I mean you have received SIGCHLD, so the child process's info is available anyway...