       // Inform the delegate.
       context.delegateQueue.sync {
         context.executorDelegate.jobStarted(job: job, arguments: arguments, pid: pid)
-        knownPId.insert(pid)
-      }
+      }
+      pendingFinish = true
 
       let result = try process.waitUntilExit()
       let success = result.exitStatus == .terminated(code: EXIT_SUCCESS)

      }
      // Only inform finished job if the job has been started, otherwise the build
      // system may complain about malformed output
      if (knownPId.contains(pid)) {
        context.delegateQueue.sync {
          let result = ProcessResult(
            arguments: [],

      context.delegateQueue.sync {
        context.executorDelegate.jobFinished(job: job, result: result, pid: pid)
      }
      pendingFinish = false
      context.cancelBuildIfNeeded(result)
      if !context.isBuildCancelled {
        try context.addRuleBeyondMandatoryCompiles(finishedJob: job, result: result)
