Reinforce handling of external processes and wait()

Didn't run into concrete issues, but recent experiments prove we
should be extra careful with this. See #1905