Question
Why is a launcher returning zero insufficient evidence that its hardware job succeeded?
Short answer
A launcher’s exit status §13.24 of 0 shows only that the launcher reached the point where its author chose to report success, which usually comes before the hardware job ends. Many launchers only hand the job to a worker process or a device, then exit. Afterwards the worker can fail, the device can still be working and output records can be missing. Success must be shown by the job’s own evidence, checked item by item: the worker’s result, the device’s report of completion and a complete, valid set of outputs.
Terms in the question
Launcher: a program whose task is to start other work, for example a script that starts a worker process in the background or submits a request to a job queue, and then ends.
Exit status, also called return code or exit code: the small integer that a process, meaning a running program, hands to its parent, the process that started it, when it ends. By convention 0 reports success and other values report failure or another outcome. On systems that follow POSIX (Portable Operating System Interface), the standard interface of Unix-like systems such as Linux, a parent that reads the status with
waitorwaitpidreceives only the lowest 8 bits of the status, a value from 0 to 255. A process killed by a signal, a notice from the kernel that can end it, has no exit status; the parent learns the signal number instead.Hardware job: work that a device carries out, not the host computer, such as writing a program into the flash memory §6.6 of a device, running a measurement or sending data by radio.
Asynchronous completion §9.28: the pattern in which the call that starts an operation returns before the operation has ended, and a later, separate event reports how the operation ended.
Full answer
The operating system only carries the number. The kernel passes the status from child to parent and attaches no meaning to it. The meaning of 0 is chosen by whoever wrote the launcher, through the place in the code where the launcher ends with 0. The first question about any launcher is therefore which event its 0 stands for. In time order, the candidates are:
the request was submitted;
the worker started;
the worker ended and reported success;
the device reported that its operation completed;
the outputs were checked and found complete and valid.
These are five different claims. A 0 tied to an early event says nothing about the later ones.
Most launchers report an early event. A job that takes minutes is started asynchronously: the launcher starts a worker in the background, or submits the job to a scheduler, and exits so that its caller can continue. For example, sbatch, the command that submits batch jobs to the Slurm workload manager, exits with 0 as soon as the scheduler has accepted the job, before the job has run. That 0 is a true report of a successful submission. Read as a report that the job succeeded, it is false.
A launcher that waits can still lose a failure.
The status is overwritten. A shell script ends with the status of its last command. If the worker fails and the next line writes a log entry successfully, the script reports 0.
A pipeline reports its last command. In the bash shell, the status of
run_job | tee log.txtis the status oftee, which copied the output successfully, unless the shell optionpipefailis set.The status is truncated. A program that exits with its number of failed checks hands its parent only the remainder of that number after division by 256.
The host is not the device. When a worker on the host ends with 0, the host’s part is done: for example, the command bytes have left the host. The device may still be carrying out the operation, may have rejected it, or may have restarted part way through. Only evidence that the device itself produces shows that the device operation completed: a completion message, a status read back from the device, or an output that only the device can produce. Whether every process of the job has ended, called process closure §13.23, is yet another fact. A launcher can exit while the worker it started is still running.
The outputs decide the result. A job defined as three measurement runs, each producing one record, succeeded only if three valid records exist and each comes from this job. A record counts when it is complete, parses correctly and carries this job’s identifier, so that a record left over from an earlier job is not counted. A missing record proves less than it seems. The recording can fail while the device completes the operation, and the device’s state is then unknown, not unchanged. This matters before a retry: an operation that is not idempotent §8.31, meaning that doing it twice has a different effect from doing it once, must not be repeated without first reading the state of the device.
What to record instead. Record each layer separately: the submission status; the exit status or ending signal of every worker; whether every process of the job has ended; the device’s evidence of completion; the number and validity of the outputs; and whether the attempt is eligible to count as evidence. Declare the job successful only when every required item passes. A wrapper, meaning a program that runs another program, must report a failure of any child instead of replacing it with its own success.
Worked example
A job requires three records, one per measurement run. These are the events, with times counted from the start.
0.0 s: the launcher asks a service manager, a program that starts and watches background processes, to run the worker.
0.3 s: the launcher exits with status 0.
15 s and 27 s: the worker writes records 1 and 2.
33 s: during run 3, the out-of-memory killer of Linux, which kills processes when memory runs out, stops the worker with signal 9. The service manager records that signal. A bash shell would show such an end as the value , which is a convention of the shell, not an exit status.
41 s: the device finishes operation 3 and sends its completion message. No process is reading, so record 3 is never written.
The evaluation, item by item:
Launcher status 0: true, and it means only that the worker was started.
Worker: ended by signal 9, so it failed.
Records: 2 are present and 3 are required; since , the output is incomplete.
Device: operation 3 did complete, but no record shows it, so from the recorded evidence its state is unknown.
Verdict: the job failed, and run 3 does not count. Before operation 3 is repeated, the state of the device must be read, because operation 3 may have taken effect; in this case it did.
Truncation sets a second trap. A checking program that exits with its number of failed checks calls exit(256) after 256 failures. The parent receives the remainder of 256 after division by 256, which is : success. After 300 failures it receives .
Follow-up questions and limits
Is a nonzero status then proof of failure? No. Each program defines its own values. The search tool grep exits with 1 when no line matched, which is a normal result, and with 2 when an error occurred.
Is it enough for the launcher to wait for the device? Only if the wait ends on evidence from the device and has a timeout §9.34. A wait that runs out of time must be reported as unknown, not as success.
Could the records come from another job? Yes, if another job used the same device in the meantime. A lease, a grant of exclusive use that expires, keeps other jobs off the device, and a job identifier in every record ties each record to its job.
This answer does not cover how to recover a device that was left in the middle of an operation.
Fullest treatment: Exit status (§13.24).
Related entries: Process closure (§13.23), Lease and exclusive ownership (§13.26), Evidence eligibility (§13.14), Asynchronous completion (§9.28), Idempotency (§8.31), Deadline versus timeout (§9.34).