Index: trunk/Ohana/src/opihi/pantasks/CheckJobs.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/CheckJobs.c	(revision 4602)
+++ trunk/Ohana/src/opihi/pantasks/CheckJobs.c	(revision 4684)
@@ -12,16 +12,5 @@
   while ((job = NextJob ()) != NULL) {
 
-    /* check for timeout - only local jobs timeout here */
-    if ((job[0].mode == JOB_LOCAL) && (GetTaskTimer(job[0].start) >= job[0].task[0].timeout_period)) {
-      if (VerboseMode()) fprintf (stderr, "timeout on %s\n", job[0].task[0].name);
-      /* run task[0].timeout macro, if it exists */
-      if (job[0].task[0].timeout != NULL) {
-	exec_loop (job[0].task[0].timeout);
-      }
-      DeleteJob (job);
-      continue;
-    }
-
-    /* check poll period (ready to run again?) */
+    /* check poll period (ready to ask for status?) */
     if (GetTaskTimer(job[0].last) < job[0].task[0].poll_period) continue;
 
@@ -74,4 +63,23 @@
     }
 
+    /* check for timeout - (local jobs only) 
+       we only check timeout after a poll (forces at least one poll)
+     */
+    if (job[0].mode == JOB_LOCAL) {
+      if (GetTaskTimer(job[0].start) < job[0].task[0].timeout_period) continue;
+      if (VerboseMode()) fprintf (stderr, "timeout on %s\n", job[0].task[0].name);
+      if (!KillLocalJob (job)) {
+	job[0].state = JOB_HUNG;
+	if (VerboseMode()) fprintf (stderr, "child process %d is hung, cannot kill\n", job[0].pid);
+	continue;
+      }
+      /* run task[0].timeout macro, if it exists */
+      if (job[0].task[0].timeout != NULL) {
+	exec_loop (job[0].task[0].timeout);
+      }
+      DeleteJob (job);
+      continue;
+    }
+
     /* reset polling clock */
     SetTaskTimer (&job[0].last);
@@ -79,2 +87,24 @@
   return (TRUE);
 }
+
+/* 
+
+  job / task timeline:
+
+  task:
+  0           exec     
+  start       create
+  task clock  new job
+
+  job:
+  0           1xpoll     2xpoll     3xpoll
+  start       check      check      check 
+  job clock   status     status     status
+
+  .           .          .          timeout
+                                    run
+				    timeout
+
+  must be at least one poll before timeout 
+  (timeout >= poll)
+*/
