Index: /trunk/Ohana/src/opihi/include/pcontrol.h
===================================================================
--- /trunk/Ohana/src/opihi/include/pcontrol.h	(revision 17475)
+++ /trunk/Ohana/src/opihi/include/pcontrol.h	(revision 17476)
@@ -10,4 +10,5 @@
   PCONTROL_JOB_PENDING,
   PCONTROL_JOB_BUSY,  
+  PCONTROL_JOB_RESP,  
   PCONTROL_JOB_HUNG,  
   PCONTROL_JOB_DONE,  
Index: /trunk/Ohana/src/opihi/pcontrol/CheckBusyJob.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/CheckBusyJob.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/CheckBusyJob.c	(revision 17476)
@@ -36,5 +36,5 @@
       if (DEBUG || VerboseMode()) gprint (GP_ERR, "message received (CheckBusyJob)");
       PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM);
-      PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);
+      PutJob (job, PCONTROL_JOB_RESP, STACK_BOTTOM);
       return (TRUE);
 
Index: /trunk/Ohana/src/opihi/pcontrol/CheckDoneHost.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/CheckDoneHost.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/CheckDoneHost.c	(revision 17476)
@@ -39,5 +39,4 @@
   /* job must have assigned host */
   ASSERT (host, "missing host");
-  ASSERT (host[0].job, "missing job");
   buffer = &host[0].comms_buffer;
 
Index: /trunk/Ohana/src/opihi/pcontrol/CheckRespHost.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/CheckRespHost.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/CheckRespHost.c	(revision 17476)
@@ -28,4 +28,8 @@
       }
 
+      // clear the response data
+      host[0].response_state = PCONTROL_RESP_NONE;
+      host[0].response = NULL;
+
       // host has shutdown; harvest the defunct process
       HarvestHost (host[0].pid);
@@ -37,5 +41,5 @@
       PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM);
       if (job) {
-	PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);
+	PutJob (job, PCONTROL_JOB_RESP, STACK_BOTTOM);
       }
       if (DEBUG || VerboseMode()) gprint (GP_ERR, "host %s is not responding\n", host[0].hostname);
@@ -52,26 +56,32 @@
   switch (host[0].response_state) {
     case PCONTROL_RESP_START_JOB:
+      if (DEBUG) fprintf (stderr, "PCONTROL_RESP_START_JOB\n");
       status = StartJobResponse (host);
-      return (status);
+      break;
 
     case PCONTROL_RESP_CHECK_HOST:
+      if (DEBUG) fprintf (stderr, "PCONTROL_RESP_CHECK_HOST\n");
       status = CheckHostResponse (host);
-      return (status);
+      break;
 
     case PCONTROL_RESP_CHECK_DONE_HOST:
+      if (DEBUG) fprintf (stderr, "PCONTROL_RESP_CHECK_DONE_HOST\n");
       status = CheckDoneHostResponse (host);
-      return (status);
+      break;
 
     case PCONTROL_RESP_CHECK_BUSY_JOB:
+      if (DEBUG) fprintf (stderr, "PCONTROL_RESP_BUSY_JOB\n");
       status = CheckBusyJobResponse (host);
-      return (status);
+      break;
 
     case PCONTROL_RESP_KILL_JOB:
+      if (DEBUG) fprintf (stderr, "PCONTROL_RESP_KILL_JOB\n");
       status = KillJobResponse (host);
-      return (status);
+      break;
 
     case PCONTROL_RESP_STOP_HOST:
+      if (DEBUG) fprintf (stderr, "PCONTROL_RESP_STOP_HOST\n");
       status = StopHostResponse (host);
-      return (status);
+      break;
 
     default:
@@ -79,5 +89,8 @@
   }
 
-  ABORT ("should not be able to get here");
+  // we have detected a valid response, clear the response data
+  host[0].response_state = PCONTROL_RESP_NONE;
+  host[0].response = NULL;
+  return (status);
 }      
 
Index: /trunk/Ohana/src/opihi/pcontrol/CheckSystem.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/CheckSystem.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/CheckSystem.c	(revision 17476)
@@ -264,18 +264,33 @@
   struct timeval start, stop;
   int i, Nobject;
-  Stack *stack;
-  Host  *host;
-  float dtime;
-
-  /* Loop through objects on the stack, no more than once. see note above */
-  stack = GetHostStack (PCONTROL_HOST_RESP);
-  Nobject = stack[0].Nobject;
-
-  /* always allow at least one test */
-  gettimeofday (&start, (void *) NULL);
-  dtime = 0.0;
-  for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) {
-    host = PullStackByLocation (stack, STACK_TOP);
-    if (host == NULL) break;
+  Stack *hoststack;
+  Stack *jobstack;
+  Host *host;
+  Job *job;
+  float dtime;
+
+  /* Loop through objects on the stack, no more than once. see note above */
+  hoststack = GetHostStack (PCONTROL_HOST_RESP);
+  jobstack = GetJobStack (PCONTROL_JOB_RESP);
+  Nobject = hoststack[0].Nobject;
+
+  /* always allow at least one test */
+  gettimeofday (&start, (void *) NULL);
+  dtime = 0.0;
+  for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) {
+    LockStack (jobstack);
+    host = PullStackByLocation (hoststack, STACK_TOP);
+    if (host == NULL) {
+	UnlockStack (jobstack);
+	break;
+    }
+
+    // if the host has a job, we need to pull the job from its stack
+    job = (Job *) host[0].job;
+    if (job != NULL) {
+	RemoveStackByID (jobstack, job[0].JobID);
+    }
+    UnlockStack (jobstack);
+
     CheckRespHost (host);
     gettimeofday (&stop, (void *) NULL);
Index: /trunk/Ohana/src/opihi/pcontrol/HostOps.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/HostOps.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/HostOps.c	(revision 17476)
@@ -78,4 +78,6 @@
   Stack *stack;
 
+  // fprintf (stderr, "move host %s to %s\n", host[0].hostname, GetHostStackName(StackID));
+
   stack = GetHostStack (StackID);
   if (stack == NULL) return (FALSE);
Index: /trunk/Ohana/src/opihi/pcontrol/JobOps.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/JobOps.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/JobOps.c	(revision 17476)
@@ -3,4 +3,5 @@
 Stack *JobPool_Pending;
 Stack *JobPool_Busy;
+Stack *JobPool_Resp;
 Stack *JobPool_Done;
 Stack *JobPool_Kill;
@@ -11,4 +12,5 @@
   JobPool_Pending = InitStack ();
   JobPool_Busy    = InitStack ();
+  JobPool_Resp    = InitStack ();
   JobPool_Done    = InitStack ();
   JobPool_Kill    = InitStack ();
@@ -28,4 +30,5 @@
   FreeJobStack (JobPool_Pending);
   FreeJobStack (JobPool_Busy   );
+  FreeJobStack (JobPool_Resp   );
   FreeJobStack (JobPool_Done   );
   FreeJobStack (JobPool_Kill   );
@@ -38,4 +41,5 @@
     case PCONTROL_JOB_PENDING: return ("PENDING");
     case PCONTROL_JOB_BUSY:    return ("BUSY");
+    case PCONTROL_JOB_RESP:    return ("RESP");
     case PCONTROL_JOB_DONE:    return ("DONE");
     case PCONTROL_JOB_KILL:    return ("KILL");
@@ -52,4 +56,5 @@
     case PCONTROL_JOB_PENDING: return (JobPool_Pending);
     case PCONTROL_JOB_BUSY:    return (JobPool_Busy);
+    case PCONTROL_JOB_RESP:    return (JobPool_Resp);
     case PCONTROL_JOB_DONE:    return (JobPool_Done);
     case PCONTROL_JOB_KILL:    return (JobPool_Kill);
@@ -66,4 +71,5 @@
   if (!strcasecmp (name, "pending")) return (JobPool_Pending);
   if (!strcasecmp (name, "busy"))    return (JobPool_Busy);
+  if (!strcasecmp (name, "resp"))    return (JobPool_Resp);
   if (!strcasecmp (name, "done"))    return (JobPool_Done);
   if (!strcasecmp (name, "exit"))    return (JobPool_Exit);
@@ -77,4 +83,6 @@
   int stat;
   Stack *stack;
+
+  // fprintf (stderr, "move job %s to %s\n", job[0].argv[0], GetJobStackName(StackID));
 
   stack = GetJobStack (StackID);
@@ -115,4 +123,8 @@
 
   *StackID = PCONTROL_JOB_BUSY;
+  job = PullJobFromStackByID (*StackID, JobID);
+  if (job != NULL) return (job);
+
+  *StackID = PCONTROL_JOB_RESP;
   job = PullJobFromStackByID (*StackID, JobID);
   if (job != NULL) return (job);
Index: /trunk/Ohana/src/opihi/pcontrol/KillJob.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/KillJob.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/KillJob.c	(revision 17476)
@@ -28,5 +28,5 @@
       FlushIOBuffer (&host[0].comms_buffer);
       PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM);
-      PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);
+      PutJob (job, PCONTROL_JOB_RESP, STACK_BOTTOM);
       return (TRUE);
 
Index: /trunk/Ohana/src/opihi/pcontrol/PclientCommand.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/PclientCommand.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/PclientCommand.c	(revision 17476)
@@ -6,5 +6,4 @@
 
   int status;
-  IOBuffer buffer;
 
   ASSERT (host != NULL, "host missing");
@@ -12,8 +11,9 @@
 
   // flush the stdout and stderr buffers here
-  ReadtoIOBuffer (&buffer, host[0].stdout_fd);
-  FlushIOBuffer (&buffer);
-  ReadtoIOBuffer (&buffer, host[0].stderr_fd);
-  FlushIOBuffer (&buffer);
+  // recycle comms_buffer to minimize page thrashing
+  ReadtoIOBuffer (&host[0].comms_buffer, host[0].stdout_fd);
+  FlushIOBuffer (&host[0].comms_buffer);
+  ReadtoIOBuffer (&host[0].comms_buffer, host[0].stderr_fd);
+  FlushIOBuffer (&host[0].comms_buffer);
 
   /* send command to client (adding on \n) */
@@ -30,4 +30,6 @@
   host[0].response = response;
   FlushIOBuffer (&host[0].comms_buffer);
+
+  // fprintf (stderr, "command: %s\n", command);
 
   return (PCLIENT_GOOD);
@@ -67,9 +69,5 @@
   if (status == -1) return (PCLIENT_HUNG);
 
-  // fprintf (stderr, "buffer.buffer: %s\n", buffer[0].buffer);
-
-  // we have detected a valid response, clear the response data
-  host[0].response_state = PCONTROL_RESP_NONE;
-  host[0].response = NULL;
+  // fprintf (stderr, "response: %s\n", buffer[0].buffer);
 
   return (PCLIENT_GOOD);
Index: /trunk/Ohana/src/opihi/pcontrol/StartJob.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/StartJob.c	(revision 17475)
+++ /trunk/Ohana/src/opihi/pcontrol/StartJob.c	(revision 17476)
@@ -48,5 +48,5 @@
       if (VerboseMode()) gprint (GP_ERR, "started job on host %s\n", host[0].hostname);  
       PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM);
-      PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);
+      PutJob (job, PCONTROL_JOB_RESP, STACK_BOTTOM);
       return (TRUE);
 
