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 Waiting for childeren in a Photon app causes an infinite loop
Ref. No. QNX.000009889
Category(ies) Development
Issue PtPrintSelection is called from our application where the user can start a preview process. When we terminate and wait() for all children to die, our process waits forever because of this preview process, and we do not know how to kill it.

Our program then hangs because we are waiting for a child to die but our program is not notified of it's termination.

So, our question is:
How do we know for which children we can wait and for which we can't?

Solution The answer is:
- wait for the children that you started. Children started by photon library will be taken care of by the library.

Since you are using a library that spawns child processes and tries to deal with their termination, calling wait() is not the right way to do that. This is due to the fact that the Photon library will not work correctly after your call to wait() steals the exit status of our child process.
Also the child won't always be run with the NOZOMBIE flag set. Besides, a blocking call like wait() prevents your application from processing Photon events.

The preferred solution is to use PtSpawn() to start child processes. PtSpawn() attaches a signal handler for SIGCHLD that calls waitpid() and invokes a callback when the child has died.
If all you want to know is when all your children have terminated, a simple counter in a global variable should do the trick.
Then your loop could be changed to something like this:

x09while(children_still_alive != 0)
x09x09PtBkgHandlerProcess();