better way to detect subprocess termination: waitpid