Index: trunk/Ohana/src/opihi/pcontrol/StopHosts.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/StopHosts.c	(revision 8296)
+++ trunk/Ohana/src/opihi/pcontrol/StopHosts.c	(revision 8424)
@@ -19,5 +19,4 @@
 int DownHosts () {
 
-  int i, Nobject;
   Stack *stack;
   Host  *host;
@@ -68,10 +67,19 @@
 int HarvestHost (int pid) {
   
-  int       result;
-  int       waitstatus;
+  int i, result, waitstatus;
 
-  /* I probably should loop a few time with max timeout larger than 10ms... */
-  usleep (10000);
-  result = waitpid (pid, &waitstatus, WNOHANG);
+  gprint (GP_ERR, "harvesting within thread %d\n", pthread_self());
+  gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid);
+  
+  // Loop a few times waiting for child to exit
+  for (i = 0; i < 50; i++) {
+    result = waitpid (pid, &waitstatus, WNOHANG);
+    if ((result == -1) && (errno == ECHILD)) {
+      usleep (10000);
+      continue;
+    } else {
+      break;
+    }
+  }
   switch (result) {
     case -1:  /* error with waitpid */
@@ -81,13 +89,9 @@
 	  gprint (GP_ERR, "did process already exit?  programming error?\n");
 	  break;
+	case EINTR:
 	case EINVAL:
-	  gprint (GP_ERR, "error EINVAL (waitpid): programming error\n");
-	  exit (1);
-	case EINTR:
-	  gprint (GP_ERR, "error EINTR (waitpid): programming error\n");
-	  exit (1);
 	default:
-	  gprint (GP_ERR, "unknown error for waitpid (%d): programming error\n", errno);
-	  exit (1);
+	  perror ("unexpected error");
+	  ABORT ("(HarvestHost)");
       }
       break;
