Learning center

An empty log does not mean the process did nothing

A process that is killed loses whatever its output buffer still holds. Before you conclude that a job never started, check how it ended and whether its output was buffered.

Lines that were printed and never written#

Each program printed at once, waited, and was killed after one or two seconds with output redirected to a file:

ProgramSignalPrintedIn the file
Python, two linesKILL2 lines0 bytes
Python with -u, two linesKILL2 lines2 lines
Python, 2,000 linesKILL2,000 lines41,014 bytes, ending mid-line in processing order
Python, 2,000 linesTERM2,000 lines41,014 bytes, the same cut
Node 24, two linesKILL2 lines2 lines
grep in a pipeline, three matchesKILL3 lines0 bytes

The last complete line in the third file was processing order 1913. The program had printed up to 1999. Taking the last line as the place where the job stopped would be wrong by 86 orders. Run with Python 3.12.

TERM behaved like KILL here, because Python's default response to it ends the process without flushing. A program that handles the signal and exits normally flushes. Node's lines survived in this fixture, which wrote to a file; do not extend that to pipes without testing.

The grep row is a reminder that a filter in front of the file buffers too. grep --line-buffered writes each match.

Separate "never ran" from "lost"#

EvidenceNever startedRan and lost output
Exit status126, 127, or a scheduler error137 or 143
File the job creates firstAbsentPresent
Database rows or requests it makesNone in the windowSome
Start recorded by the schedulerNoYes
Log ends in the middle of a lineNo logA strong sign of a cut buffer

137 is 128 plus signal 9, so the process received KILL. It does not say who sent it: the kernel's memory killer, a container runtime and a person all produce it. Read the memory events or the runtime's record before you write "out of memory".

Change the capture before the next run#

  • Python: PYTHONUNBUFFERED=1, or print(..., flush=True) at the lines that mark progress.
  • C programs that use stdio: stdbuf -oL command, when the program does not set its own buffering.
  • Progress that matters: write it to the database in the same transaction as the work. A log line says the program passed a point, and a committed row says the work is done.

What to hand over#

  1. The exit status and who recorded it.
  2. The file's size and whether the last line is complete.
  3. How output was captured, with every process in the pipeline.
  4. An independent trace of progress, or the sentence "progress unknown after order 1913".

The word "after" in item 4 matters. The log gives a lower bound on progress.

Worked example#

This example is fictional. A nightly job's log is empty, and Ana hands it over as "did not run, rerun it". Ben sees status 137 and 1,950 charges created in the job's window. The job had run and lost its output. A rerun without a check would have charged those accounts again. He finds the first uncharged account from the table and resumes there.

Resuming safely is the topic of a backfill in progress. Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading