use waitpid instead of wait to avoid zombies