Index: trunk/Ohana/src/opihi/pcontrol/CheckSystem.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/CheckSystem.c	(revision 8424)
+++ trunk/Ohana/src/opihi/pcontrol/CheckSystem.c	(revision 8546)
@@ -55,6 +55,7 @@
 void *CheckSystem_Threaded (void *data) {
 
-  struct timeval now;
-  float dtime;
+  int Njobchecks, Nhostchecks, Nlivechecks;
+
+  Nlivechecks = 0;
 
   gprintInit ();
@@ -66,17 +67,20 @@
     // don't run the system checks if RunSystem is FALSE
     if (!RunSystem) {
-      usleep (50000);
+      usleep (50000); // idle if RunSystem is FALSE
       continue;
     }
 
+    Njobchecks = 0;
+    Nhostchecks = 0;
+
     // we want to give each block a maximum allowed time
-    CheckIdleHosts(0.020); /* submit a new job */
-
-    CheckBusyJobs(0.020);  /* get job status */
-    CheckDoneJobs(0.020);  /* harvest job stdout/stderr */
-    CheckKillJobs(0.020);  /* harvest job stdout/stderr */
-
-    CheckDoneHosts(0.020); /* reset the host */
-    CheckDownHosts(0.100); /* launch the host */
+    Nhostchecks += CheckIdleHosts(0.020); /* submit a new job */
+
+    Njobchecks  += CheckBusyJobs(0.020);  /* get job status */
+    Njobchecks  += CheckDoneJobs(0.020);  /* harvest job stdout/stderr */
+    Njobchecks  += CheckKillJobs(0.020);  /* harvest job stdout/stderr */
+
+    Nhostchecks += CheckDoneHosts(0.020); /* reset the host */
+    Nhostchecks += CheckDownHosts(0.100); /* launch the host */
 
     /* always allow at least one test */
@@ -84,9 +88,8 @@
        CheckDoneJobs must depend on the size of the output buffer */
 
-    gettimeofday (&now, (void *) NULL);
-    dtime = DTIME (now, lastlive);
-    if (dtime > 1.0) {
+    // there is nothing on the stacks.  test the hosts and wait a bit
+    if (!Njobchecks && !Nhostchecks) {
       CheckLiveHosts(0.040);
-      lastlive = now;
+      usleep (100000); // idle if no jobs are waiting
     } 
 
@@ -145,5 +148,5 @@
   }
   if (DEBUG && (Nobject > 0)) gprint (GP_ERR, "checked %d of %d jobs\n", i, Nobject);
-  return (TRUE);
+  return (i);
 }
 
@@ -182,5 +185,5 @@
   }
   if (DEBUG && (Nobject > 0)) gprint (GP_ERR, "checked %d of %d jobs\n", i, Nobject);
-  return (TRUE);
+  return (i);
 }
 
@@ -219,5 +222,5 @@
   }
   if (DEBUG && (Nobject > 0)) gprint (GP_ERR, "checked %d of %d jobs\n", i, Nobject);
-  return (TRUE);
+  return (i);
 }
 
@@ -245,5 +248,5 @@
   }
   if (DEBUG) gprint (GP_ERR, "checked %d hosts\n", i);
-  return (TRUE);
+  return (i);
 }
 
@@ -281,5 +284,5 @@
   }
   if (DEBUG) gprint (GP_ERR, "checked %d hosts\n", i);
-  return (TRUE);
+  return (i);
 }
 
@@ -294,5 +297,5 @@
   /* check if there are any pending jobs, otherwise skip step */
   stack = GetJobStack (PCONTROL_JOB_PENDING);
-  if (!stack[0].Nobject) return (TRUE);
+  if (!stack[0].Nobject) return (0);
 
   /* Loop through objects on the stack, no more than once. see note above */
@@ -311,5 +314,5 @@
   }
   if (DEBUG) gprint (GP_ERR, "checked %d hosts\n", i);
-  return (TRUE);
+  return (i);
 }
 
