Index: trunk/Ohana/src/opihi/pclient/reset.c
===================================================================
--- trunk/Ohana/src/opihi/pclient/reset.c	(revision 4689)
+++ trunk/Ohana/src/opihi/pclient/reset.c	(revision 4762)
@@ -4,8 +4,9 @@
 
   int i, result, waitstatus;
+  struct timespec request, remain;
 
   if (argc != 1) {
     fprintf (stderr, "USAGE: reset\n");
-    fprintf (stdout, "STATUS -1\n");
+    fprintf (GetOutfile(), "STATUS -1\n");
     return (FALSE);
   }
@@ -13,23 +14,27 @@
   if (ChildStatus == PCLIENT_NONE) {
     fprintf (stderr, "no child process, cannot reset\n");
-    fprintf (stdout, "STATUS 2\n");
+    fprintf (GetOutfile(), "STATUS 2\n");
     return (TRUE);
   }
 
+  /* avoid blocking on waitpid, test every 100 usec, up to 50 msec */
+  request.tv_sec = 0;
+  request.tv_nsec = 100000;
+
   if (ChildStatus == PCLIENT_BUSY) {
-    /* send SIGTERM signal to job */
+    /* job is still running, send SIGTERM signal to job */
     kill (ChildPID, SIGTERM);
-    result = 0;
-    for (i = 0; (i < 10) && (result == 0); i++) {
-      usleep (10000);  /* 10 ms is min */
+    result = waitpid (ChildPID, &waitstatus, WNOHANG);
+    for (i = 0; (i < 500) && (result == 0); i++) {
+      nanosleep (&request, &remain);
       result = waitpid (ChildPID, &waitstatus, WNOHANG);
     }
     if (result) goto reset_job;
 
-    /* send SIGTERM signal to job */
+    /* job did not exit, send SIGKILL signal to job */
     kill (ChildPID, SIGKILL);
-    result = 0;
-    for (i = 0; (i < 10) && (result == 0); i++) {
-      usleep (10000);  /* 10 ms is min */
+    result = waitpid (ChildPID, &waitstatus, WNOHANG);
+    for (i = 0; (i < 500) && (result == 0); i++) {
+      nanosleep (&request, &remain);
       result = waitpid (ChildPID, &waitstatus, WNOHANG);
     }
@@ -38,5 +43,5 @@
     /* total failure, don't reset */
     fprintf (stderr, "child process %d is hung, cannot reset\n", ChildPID);
-    fprintf (stdout, "STATUS 0\n");
+    fprintf (GetOutfile(), "STATUS 0\n");
     return (FALSE);
   }
@@ -57,5 +62,5 @@
   ChildExitStatus = 0;
 
-  fprintf (stdout, "STATUS 1\n");
+  fprintf (GetOutfile(), "STATUS 1\n");
   return (TRUE);
 }
@@ -68,2 +73,3 @@
 */
 
+/* the linux kernel timer sticks in a 10ms lag between kill and the harvest */
