Catch dead child processes

See discussion in #440

Please don't merge this yet - the control structure is pretty complicated, so I want to refactor this a bit.