Fix subprocess watching.

Currently, the subprocess watching code polls with a delay between attempts.
Instead, introduce wait_with_timeout() and use it, simplifying this code.

Signed-off-by: Elly Fong-Jones <elly@leptoquark.net>