+ /*
+ * The postmaster should create postmaster.pid very soon after being
+ * started. If it's not there after we've waited 5 or more seconds,
+ * assume startup failed and give up waiting. (Note this covers both
+ * cases where the pidfile was never created, and where it was created
+ * and then removed during postmaster exit.) Also, if there *is* a
+ * file there but it appears stale, issue a suitable warning and give
+ * up waiting.
+ */
+ if (i >= 5)
+ {
+ struct stat statbuf;
+
+ if (stat(pid_file, &statbuf) != 0)
+ return PQPING_NO_RESPONSE;
+
+ if (found_stale_pidfile)
+ {
+ write_stderr(_("\n%s: this data directory appears to be running a pre-existing postmaster\n"),
+ progname);
+ return PQPING_NO_RESPONSE;
+ }
+ }
+
+ /*
+ * If we've been able to identify the child postmaster's PID, check
+ * the process is still alive. This covers cases where the postmaster
+ * successfully created the pidfile but then crashed without removing
+ * it.
+ */
+ if (pm_pid > 0 && !postmaster_is_alive((pid_t) pm_pid))
+ return PQPING_NO_RESPONSE;
+