Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Using PtAppAddSignalProc()
Ref. No. QNX.000009898
Category(ies) Development
Issue Our program spawns eight subprocesses continuously, and uses PtAppAddSignalProc() to set up a signal (SIGCHLD) handler. Among the subprocesses, seven of them exit immediately. But we just catch the last subprocesses SIGCHLD signal, and lose other ones. Why?



Solution This is how signals work. If a signal is sent to a process more than once before the proces gets a chance to run the signal handler, there is no guarantee that the handler will be called more than once. In order to find out which child process(es) have genereted the signal, the handler has to call wait() or waitpid() in a loop.

But since you are using PtAppAddSignalProg, it is easier to register one instance of the signal handler per child process. This way, Photon library will run the loop for you. Or, even better, spawn your process using PtSpawn() -- The library will attach a signal handler for you and invoke a callback for each child process that terminates.