diff --git a/src/slurmd/slurmd.c b/src/slurmd/slurmd.c
index f58a0bdf6561fe1ac0e2e2dc03a1b281e7b20325..d3b1981453f2cc40b17964ccf1606828710c156a 100644
--- a/src/slurmd/slurmd.c
+++ b/src/slurmd/slurmd.c
@@ -180,11 +180,12 @@ main (int argc, char *argv[])
 
 	_msg_engine();
 
-	/* 
-	 * Close pidfile, thus releasing write lock and
-	 * allowing a waiting to continue.
+	/*
+	 * Close fd here, otherwise we'll deadlock since create_pidfile()
+	 * flocks the pidfile.
 	 */
-	(void) close(pidfd);  /* Ignore errors */
+	if (pidfd >= 0)			/* valid pidfd, non-error */
+		(void) close(pidfd);	/* Ignore errors */
 	if (unlink(conf->pidfile) < 0)
 		error("Unable to remove pidfile `%s': %m", conf->pidfile);