Add timeout on waitpid to avoid deadlocks