Fix stop_and_wait to handle ports and os_pids correctly

If the Pid passed to stop_and_wait is an os_pid, then it will never
match with the message's Pid.