Added a wait for child logic to the main thread.

The program now exits neatly.
We are still busy looping, this is bad, we should be doing some signal handling to trigger the main thread only when the children are closing out.