CronNudge

Published October 21, 2026

Cron Job Stuck or Hanging? Timeouts and Stuck-Run Alerts

The process is still there an hour later, or it never was. A ping that fires only at the end looks the same either way: silence, until the grace period ends. Cron will start the next copy while the first one is still alive. Nothing in the crontab stops that.

This page is how to tell a live process from a slow one, the limits that end it, and the CronNudge alert that fires when a start is never followed by a finish. A line that never starts at all is crontab not running. The heartbeat that only proves a finish is how to monitor cron jobs. A second copy of a long run is prevent overlapping cron jobs.

timeout below is GNU coreutils 9.4 timeout(1), the same text timeout --help prints. BusyBox timeout is a different program. The systemd sentences are systemd.service(5). Kubernetes behavior is the Job documentation, also written out in how to monitor Kubernetes CronJobs. The ping behavior is CronNudge's.

Hung, slow, or already gone

ps and pgrep answer a smaller question than "is it stuck." They answer "is this process still here, and how long has it been here."

ps -eo pid,stat,etime,lstart,args | awk '/\/usr\/local\/bin\/backup.sh/ && !/awk/'

etime is elapsed time, [[dd-]hh:]mm:ss. lstart is the wall-clock start. A backup you already know takes about ten minutes, with etime at 06:12:03, has not exited. A backup at eight minutes may still be healthy. The clock does not know your normal duration. You do.

pgrep -a -f /usr/local/bin/backup.sh prints the command line. The pattern matches the pgrep process too when that process's own arguments contain the same path. pgrep -x matches the comm name, and Linux comm is 15 characters, so a long script name does not match. Prefer the ps line above when the name is long.

The state letter is the other half:

ps state What the process is doing
R Running, or waiting for a CPU.
S Sleeping in a way a signal can interrupt: a poll, a lock wait in userspace, a read.
D Uninterruptible sleep. Usually disk or NFS. The signal is delivered when the kernel call returns.
Z Zombie. The process has already exited. The parent has not waited for it.

No row means it is not running now. It may have exited, or cron may never have started it. The daemon log is the difference. Where that log is, and where the job's own output went, is where are cron logs.

/proc/<pid>/stat start time

ps -o lstart is this field, printed as a date. Field 22 of /proc/<pid>/stat is starttime: clock ticks since boot, not a wall clock. proc(5) counts it as field 22. Divide by the CLK_TCK value getconf CLK_TCK prints, and add btime from /proc/stat, which is boot time in seconds since the epoch. Do not hard-code the tick rate.

The comm field sits in parentheses and may contain spaces, so a naive $22 counts the wrong column when the name has a space. Cut after the ) that closes comm. Field 22 is then the 20th field of what remains.

pid=12345
hz=$(getconf CLK_TCK)
btime=$(awk '/^btime / { print $2 }' /proc/stat)
ticks=$(awk -F') ' '{ split($2, f, " "); print f[20] }' "/proc/$pid/stat")
date -d "@$(( btime + ticks / hz ))"

date -d here is GNU date. The integer division drops the fraction of a second. Compare that instant with lstart once. If they disagree, the awk split missed the comm field.

systemctl status on a timer

The timer unit is the schedule. The service unit is the process. systemctl list-timers backup.timer shows the last trigger and the next elapse. It does not show that the backup is still inside ExecStart.

systemctl status backup.service
systemctl show backup.service -p ActiveState -p SubState -p ExecMainStartTimestamp

A Type=simple service that has not exited shows Active: active (running) since .... A Type=oneshot service shows Active: activating (start) since ... for the whole time ExecStart is still running, and inactive (dead) after it returns. The "since" on that line is how long this state has lasted. ExecMainStartTimestamp is when the main process started. A start timestamp from 03:00 and a state that is still activating at 09:00 is the hung oneshot.

GNU timeout

timeout runs a command and signals it if it is still running after a duration. The duration is a floating-point number. The suffix is s (the default), m, h, or d. A duration of 0 disables that timeout. On Debian the binary is /usr/bin/timeout. A user crontab whose PATH is still /usr/bin:/bin finds it. An absolute path is the line that survives a shorter PATH.

The signal is TERM unless -s / --signal says otherwise. TERM kills a process that does not block it or catch it. -s KILL sends KILL (9) instead. KILL cannot be caught.

-k / --kill-after=DURATION arms a second timer. It starts when the first signal is sent, and it sends KILL if the command is still running. If TERM already killed the command, the second timer never fires.

Without --foreground, timeout puts itself in a new process group and signals that group, so children of the command are signaled too. A child that calls setpgid and leaves the group is not. That is the same escape as a job that daemonizes out from under flock, on the overlap page.

Exit status:

What happened Status
The command finished in time The command's own status
Timed out, the signal was not KILL, and --preserve-status was not set 124
KILL was delivered to the command, or to timeout itself 137, which is 128+9
timeout failed before the exec 125
The command was found and could not be invoked 126
The command was not found 127

sleep dies from the default TERM, so timeout 1s sleep 30 exits 124, including when -k is also set. -k does not change that result, because the process is already gone. A command that ignores TERM stays alive, timeout waits with it, and -k 1s then sends KILL. That exit is 137. Without -k, timeout is still waiting after the duration. The first signal did not end the process, and nothing sends a second one.

-s KILL as the first signal exits 137. Without --foreground, timeout signals its own process group, so it is killed too. The shell reports Killed, and the status is 137 rather than 124.

--preserve-status returns the command's status instead of 124. TERM that kills the command is 143 (128+15). A command that catches TERM and exits 0 is status 0, so cron and a ?exit= ping both see success. The timeout happened. The status does not say so. Leave --preserve-status off if 124 is the signal you want.

--foreground does not create the process group. The help text says this is for when timeout is not the foreground job of an interactive shell: the command can read the terminal and receive terminal signals. In that mode, children of the command are not timed out. Cron has no terminal. The flag does not make a crontab line safer. timeout --foreground 1s /tmp/job.sh, where the script is sleep, kills the shell and leaves sleep running, reparented to pid 1. The same script without --foreground takes sleep with it and exits 124. A pipeline has the same shape. timeout 30m sh -c 'cmd | tee log' bounds both sides only when tee stays in the group. --foreground signals sh and leaves cmd and tee running.

timeout and flock -w on one crontab line

Put flock outside timeout. -w is how long to wait for the lock. The timeout is how long the command may run after the lock is held. The other order counts the wait against the command's budget, and a long wait can signal flock before the job starts.

0 3 * * * /usr/bin/flock -w 30 /var/lock/job.lock /usr/local/bin/job-ping

flock -w 30 waits up to 30 seconds. Decimal seconds are allowed. If the lock is still held, flock exits 1 and job-ping does not run. Do not pass -n and -w together. The lock file, the directory, and why deleting the file is not a release are on the overlap page. /var/lock has to exist and be writable by the crontab user.

job-ping is outside timeout, so a KILL to the command's process group does not kill the shell that still has to ping. /start is before the work. The finish ping is after timeout returns.

#!/bin/sh
# /usr/local/bin/job-ping
set -u
url="${CRONNUDGE_URL:?CRONNUDGE_URL is not set}"

host=$(uname -n 2>/dev/null || echo local)

ping() {
  curl -fsS -m 10 --retry 3 -o /dev/null \
    -H "Idempotency-Key: ${host}-$$-$1" \
    "$2" || true
}

ping start "${url}/start"
status=0
/usr/bin/timeout -k 30s 30m /usr/local/bin/job.sh || status=$?
if [ "$status" -eq 0 ]; then
  ping ok "$url"
else
  ping fail "${url}/fail?exit=${status}"
fi
exit "$status"

30m sends TERM. -k 30s sends KILL 30 seconds later if the process is still there. Status 0 pings the success URL. 124 and 137 take /fail, and ?exit= stores that code. A non-zero ?exit= on the success URL is also stored as a failure. Use /fail on the failure branch.

The key is the host name from uname -n, the shell pid, and the phase, so a curl retry of /start is a replay and the finish ping is not. Keys are truncated at 128 characters. The full rule, and why the copy that loses the lock must not call /fail, is on the overlap page.

If the crontab line is timeout around the whole script, a group KILL never reaches /fail. The run stays open. Max runtime, below, is the alert for that case. curl -m 10 on the ping is a different clock. It stops a stuck monitor call from holding the shell. --retry resets that 10 seconds on each try. --retry-max-time is the cap on the whole retry window, if you need one.

systemd: RuntimeMaxSec= and TimeoutStopSec=

A timer does not run the command and does not apply these limits. The service it starts does. After a unit edit, systemctl daemon-reload.

RuntimeMaxSec= limits how long the service may be active. Past that, systemd terminates it and puts it in a failed state. systemd.service(5) says this has no effect on Type=oneshot, because a oneshot is finished once activation completes. The limit for that activation is TimeoutStartSec=. For Type=oneshot, TimeoutStartSec= is disabled by default (infinity), even though other types inherit the manager's start timeout.

# /etc/systemd/system/backup.service
[Service]
Type=oneshot
TimeoutStartSec=30min
TimeoutStopSec=90s
ExecStart=/usr/local/bin/backup.sh

TimeoutStopSec= is the stop grace. It bounds each ExecStop= and then how long the process may take to exit. When it expires, systemd sends SIGKILL. The default is the manager's DefaultTimeoutStopSec=, which is 90 seconds unless that configuration changes it. RuntimeMaxSec= on a Type=simple or Type=exec service uses this same stop path: the runtime limit fails the unit, TERM is the usual stop signal (KillSignal=), and TimeoutStopSec= is how long until SIGKILL.

systemctl show backup.service -p TimeoutStartUSec -p RuntimeMaxUSec -p TimeoutStopUSec prints the values the manager is using. A timeout failure does not run ExecStartPost=. OnFailure= is the unit that can ping /fail. The ping unit is in systemd timers.

A process in D state still does not die at TimeoutStopSec= until the kernel call returns. The unit stays "stopping" for that long.

Kubernetes activeDeadlineSeconds

The field that ends a running Job is .spec.activeDeadlineSeconds on the Job. On a CronJob that is jobTemplate.spec.activeDeadlineSeconds, not a field of the CronJob itself, and not only the Pod template. The Job spec and the Pod template both have the name. Set the Job one. The Pod one is a different clock.

jobTemplate:
  spec:
    activeDeadlineSeconds: 1800

The count is whole seconds from when the Job becomes active. It covers the Job, including Pods created by retries. When the deadline is reached, Kubernetes terminates the running Pods and marks the Job Failed with reason DeadlineExceeded. The deadline wins over backoffLimit: no further Pod is started once the time is up, even if retries remain. A Pod stuck Pending counts. It does not move backoffLimit. The manifest and that Pending case are in the Kubernetes guide.

startingDeadlineSeconds is the other knob. It lives on the CronJob, and it is how late this occurrence may still start. It does not kill a Job that started on time and then hung. concurrencyPolicy: Forbid will not start the next Job while this one is active, so a hung Job with no deadline also skips the later schedules. That skip is the overlap page.

The killed container often never reaches /fail. /start before the work leaves the run open, and the missing finish is the alert below.

What the process is waiting on

A hung job is a process blocked on something that has no deadline of its own. The limit above is the backstop. The cause is whichever of these the stack trace, the ps state, or the server log shows.

A network call with no timeout. curl has no transfer limit unless you set one. -m / --max-time is the maximum time for the whole transfer. --connect-timeout is only the connection phase: DNS and the TCP, TLS, or QUIC handshake. Once curl has connected, that option does not apply, and a server that accepts and sends nothing holds the job until -m fires. curl exits 28 on either timeout. --retry starts the -m clock over on each attempt. A client library that defaults to no timeout does the same thing curl does with neither flag. Put the deadline on the call the job makes, and keep timeout around the process for the call that forgot one.

A database lock. The client is alive, state S, waiting on another transaction. PostgreSQL statement_timeout and lock_timeout both default to 0, which disables the limit. Set them on the session the job opens. Killing the client ends the wait when the session dies. A lock timeout ends it without a kill. The OS view cannot see the other session. The database can.

Stdin, or a prompt that wanted a terminal. With no % in the crontab command, cron opens stdin on /dev/null, so a plain read gets end of file. It does not sit there. % is special: the first unescaped % becomes a newline, and the text after it is stdin. The rule is in crontab not running. What does wait is a program that opens /dev/tty for a password or a host-key question (sudo, ssh without BatchMode=yes, a pinentry), or a pipe or fifo whose writer never closes. A container started with stdin open and nothing writing is the same wait. Cron's /dev/null is not that container.

A full disk. A write on a full filesystem usually fails with ENOSPC. It does not, by itself, sleep forever. df -h is the space check. df -i is the inode check. A process whose state is D during a write is stuck in the kernel, and a signal does not finish that wait. That shows up when the disk cannot complete the write, including a filesystem that is not merely full but not answering.

NFS. A hard mount, which is the default, retries an unresponsive server with no deadline. The process sits in D. TERM and KILL are delivered when the RPC returns. timeout -s KILL does not clear it before then, and neither does TimeoutStopSec=. A soft mount returns an error after its retransmissions. A lock file on NFS is a separate problem: flock there is not a distributed lock until two hosts have been shown to exclude each other. That test is on the overlap page.

A finish ping cannot see a hang yet

A check that only receives the success URL has one fact. The ping arrived, or it did not. A job that never started and a job that started and hung both produce no ping. Grace is measured from the scheduled time, not from the moment the process appeared. Until that deadline, the two failures are the same silence. When the deadline passes, the alert is the down alert: no successful ping arrived by the deadline. The text does not say the process is still running. CronNudge has not been told that it is.

The default grace is 5 minutes. The form offers none, 1 minute, 5 minutes, 15 minutes, and 1 hour. The API accepts any whole number of seconds from 0 through 7 days. Grace is how late the schedule may be. A job that legitimately runs 20 minutes, with the default grace and a ping only at the end, is marked down while it is still working. That down alert means the success ping has not arrived. It is not a measurement of the process. Lengthen grace past a healthy run, or ping /start and set a max runtime.

What CronNudge does with /start

The ping URL is https://cronnudge.com/ping/<check-id>. GET, POST, and HEAD all count. Store it in CRONNUDGE_URL with no query string and no /start suffix.

Turn on "Track start and finish." Setting Max runtime (seconds) or Duration deviation % turns run tracking on as well. /start records a start. It is not a success. It leaves the run open. A second /start while a run is open is an overlap alert, and it does not close the first run. A success ping or /fail closes every open run for the check.

/fail marks the check down and alerts immediately when it was not already down. That is the 124 from the wrapper. The stuck alert is the other path: the finish ping never comes.

Max runtime is allowed from 1 second through 7 days. When it is set and a run is open, the deadline becomes that start time plus that many seconds. The schedule's own grace is not the earlier of the two. The sweep then marks the check down and sends the stuck alert: the check is still running, and it passed its max runtime without a finish ping. The alert fires once for that start. A later success ping is the recovery.

The clock moves to the latest /start. A second start, which also alerts overlap, starts the max-runtime count over from that later start.

With run tracking and no max runtime, an open run is due after the grace period, and that wait is at least 60 seconds even when grace is none. On a nightly schedule the next slot is tomorrow, so the open-run deadline is the one that fires. With the default 5-minute grace, a job that takes 20 minutes is marked down while it is still running. That alert is the down alert, not the stuck alert. Set Max runtime longer than a healthy run when you ping /start.

A check that never pings /start cannot produce the stuck alert. Stuck requires run tracking, an open run, a max runtime, and a start time. Silence until grace is down, whether the process is hung or absent.

Duration deviation % is a different signal. It compares the new duration with the median of earlier successful runs, after at least three samples, using up to the last 20. The duration is the time from the latest /start to the success ping. The alert does not, by itself, mark the check down. The percent has to be from 1 to 1000. A run with no finish has no duration yet, so this is not the stuck signal.

A paused check records the ping and does not alert.

Free includes output assertions and run tracking on 3 checks. Pro removes that cap. The cap does not change the check count. Free is 10 checks and a 5-minute minimum interval. Pro is $12 a month for 100 checks and a 1-minute minimum. Token and dollar limits are a different feature, on Pro, and this check does not use them. The numbers are on pricing. The field list is assertions, runs, and agents. Match the five fields on the cron tool. One check per job.

FAQ

How do I tell a hung cron job from a slow one? Find the process. ps shows etime and lstart. pgrep prints the command line and can match itself. Field 22 of /proc/PID/stat is the start time in clock ticks since boot. Add btime from /proc/stat and divide by CLK_TCK. For a timer, systemctl status on the service shows activating or running, and since when. The timer unit is only the schedule. Compare that elapsed time with a run length you already trust. No process means it is not running now.

What does GNU timeout exit with? 124 when the command times out, the signal was not KILL, and --preserve-status is not set. 137 (128+9) when KILL is delivered, including -s KILL and a --kill-after that actually fires. If TERM already killed the command, --kill-after does not fire and the status stays 124. 125, 126, and 127 are failures of timeout itself. --preserve-status returns the command's status, so a handler that exits 0 hides the timeout. A command killed by TERM is 143 in that mode.

Why did timeout leave the job running? The default signal is TERM. A process that ignores it keeps running unless -k sends KILL after a further delay. Without -k, timeout waits until the command exits. --foreground signals only the direct child, so a script's children keep running. Cron has no terminal, and that flag is the wrong one there. A process in D state, including an NFS hard mount, does not die until the kernel call returns.

Does a ping at the end tell a hang from a missed start? No. Both are silence until grace ends, and the alert is the same down alert: no successful ping arrived. Grace is measured from the scheduled time. The form offers none, 1 minute, 5 minutes (the default), 15 minutes, and 1 hour. The API accepts any whole number of seconds from 0 through 7 days. Ping /start and set a max runtime to get the stuck alert instead.

How does CronNudge alert on a stuck run? Turn on run tracking, or set Max runtime, which turns it on. Ping /start, then the success URL or /fail. Max runtime is 1 second through 7 days. When the open run passes it, the sweep sends one stuck alert and marks the check down. A success ping is the recovery. Without a max runtime the open run uses grace, at least 60 seconds, and the alert is down, not stuck. Free includes run tracking on 3 checks. Pro removes that cap. Free is 10 checks at a 5-minute minimum. Pro is $12 a month for 100 checks at a 1-minute minimum.

Does RuntimeMaxSec= limit a Type=oneshot service? No. RuntimeMaxSec= has no effect on Type=oneshot. Use TimeoutStartSec= for that activation. It is disabled by default on oneshot. TimeoutStopSec= is how long systemd waits after the stop signal before SIGKILL. The manager default is 90 seconds unless DefaultTimeoutStopSec= changes it. On Kubernetes the Job field is activeDeadlineSeconds. startingDeadlineSeconds is how late the CronJob may still start, and it does not kill a Job that is already running.


The process is still on the machine, or the finish ping is not coming. Create the check, or read how to monitor cron jobs if the schedule itself never fires. Related: prevent overlapping cron jobs, Kubernetes CronJobs, and systemd timers.