       if error is DiagnosticData {
         context.diagnosticsEngine.emit(error)
       }
-      context.delegateQueue.async {
-        let result = ProcessResult(
-          arguments: [],
-          environment: env,
-          exitStatus: .terminated(code: EXIT_FAILURE),
-          output: Result.success([]),
-          stderrOutput: Result.success([])
-        )
-        context.executorDelegate.jobFinished(job: job, result: result, pid: 0)
+      // 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.async {
+          let result = ProcessResult(
+            arguments: [],
+            environment: env,
+            exitStatus: .terminated(code: EXIT_FAILURE),
+            output: Result.success([]),
+            stderrOutput: Result.success([])
+          )
+          context.executorDelegate.jobFinished(job: job, result: result, pid: pid)
+        }
       }
       value = .jobExecution(success: false)
     }

      // Inform the delegate.
      context.delegateQueue.async {
        context.executorDelegate.jobStarted(job: job, arguments: arguments, pid: pid)
      }

      let result = try process.waitUntilExit()

    let env = context.env.merging(job.extraEnvironment, uniquingKeysWith: { $1 })

    let value: DriverBuildValue
    var knownPId = Set<Int>()
    var pid = 0
    do {
      let arguments: [String] = try resolver.resolveArgumentList(for: job,
