Skip to content
Latchkey

timeout Command Reference for CI Scripts

timeout runs a command and kills it if it exceeds a time limit.

timeout is the guard against a single stuck command hanging an entire job until the much longer CI-level timeout fires. It is essential around network waits and follows.

Common flags/usage

  • timeout DURATION CMD: e.g. timeout 30 or timeout 5m
  • -k DURATION: send SIGKILL this long after the initial signal
  • -s SIGNAL: choose the signal sent on timeout (default TERM)
  • --preserve-status: exit with the command\u2019s own status
  • Exit 124 means the command was timed out

Example

shell
timeout 60 ./wait-for-service.sh || { echo "Service never came up"; exit 1; }
timeout -k 10 5m npm run integration-tests

In CI

timeout exits 124 when the command runs too long, which lets you detect a hang and fail with a clear message instead of waiting for the job timeout. Some processes ignore SIGTERM; add -k to follow up with SIGKILL. Wrap blocking commands like tail -f or a health-check loop in timeout so they cannot stall the runner.

Key takeaways

  • timeout 124 signals the command was killed for exceeding its limit.
  • Add -k to escalate to SIGKILL for processes that ignore SIGTERM.
  • Wrap blocking commands like tail -f so they cannot hang the job.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →