fix zombie issue

Avoid zombie children by waiting for them after they have been
terminated.