{
    "mode": "info",
    "parameter": "timeout",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/timeout/json",
    "generated": "2026-09-04T02:08:40Z",
    "sections": {
        "File: coreutils.info,  Node: timeout invocation,  Prev: stdbuf invocation,  Up: Modified command invocation": {
            "content": "",
            "subsections": [
                {
                    "name": "23.6 'timeout': Run a command with a time limit",
                    "content": "'timeout' runs the given COMMAND and kills it if it is still running\nafter the specified time interval.  Synopsis:\n\ntimeout [OPTION] DURATION COMMAND [ARG]...\n\nCOMMAND must not be a special built-in utility (*note Special\nbuilt-in utilities::).\n\nThe program accepts the following options.  Also see *note Common\noptions::.  Options must precede operands.\n\n'--preserve-status'\nReturn the exit status of the managed COMMAND on timeout, rather\nthan a specific exit status indicating a timeout.  This is useful\nif the managed COMMAND supports running for an indeterminate amount\nof time.\n\n'--foreground'\nDon't create a separate background program group, so that the\nmanaged COMMAND can use the foreground TTY normally.  This is\nneeded to support two situations when timing out commands, when not\ninvoking 'timeout' from an interactive shell.\n1. COMMAND is interactive and needs to read from the terminal for\nexample\n2. the user wants to support sending signals directly to COMMAND\nfrom the terminal (like Ctrl-C for example)\n\nNote in this mode of operation, any children of COMMAND will not be\ntimed out.  Also SIGCONT will not be sent to COMMAND, as it's\ngenerally not needed with foreground processes, and can cause\nintermittent signal delivery issues with programs that are monitors\nthemselves (like GDB for example).\n\n'-k DURATION'\n'--kill-after=DURATION'\nEnsure the monitored COMMAND is killed by also sending a 'KILL'\nsignal.\n\nThe specified DURATION starts from the point in time when 'timeout'\nsends the initial signal to COMMAND, i.e., not from the beginning\nwhen the COMMAND is started.\n\nThis option has no effect if either the main DURATION of the\n'timeout' command, or the DURATION specified to this option, is 0.\n\nThis option may be useful if the selected signal did not kill the\nCOMMAND, either because the signal was blocked or ignored, or if\nthe COMMAND takes too long (e.g.  for cleanup work) to terminate\nitself within a certain amount of time.\n\n'-s SIGNAL'\n'--signal=SIGNAL'\nSend this SIGNAL to COMMAND on timeout, rather than the default\n'TERM' signal.  SIGNAL may be a name like 'HUP' or a number.  *Note\nSignal specifications::.\n\n'-v'\n'--verbose'\nDiagnose to standard error, any signal sent upon timeout.\n\nDURATION is a floating point number in either the current or the C\nlocale (*note Floating point::) followed by an optional unit:\n's' for seconds (the default)\n'm' for minutes\n'h' for hours\n'd' for days\nA duration of 0 disables the associated timeout.  Note that the\nactual timeout duration is dependent on system conditions, which should\nbe especially considered when specifying sub-second timeouts.\n\nExit status:\n\n124 if COMMAND times out, and '--preserve-status' is not specified\n125 if 'timeout' itself fails\n126 if COMMAND is found but cannot be invoked\n127 if COMMAND cannot be found\n137 if COMMAND or 'timeout' is sent the KILL(9) signal (128+9)\nthe exit status of COMMAND otherwise\n\nIn the case of the 'KILL(9)' signal, 'timeout' returns with exit\nstatus 137, regardless of whether that signal is sent to COMMAND or to\n'timeout' itself, i.e., these cases cannot be distinguished.  In the\nlatter case, the COMMAND process may still be alive after 'timeout' has\nforcefully been terminated.\n\nExamples:\n\n# Send the default TERM signal after 20s to a short-living 'sleep 1'.\n# As that terminates long before the given duration, 'timeout' returns\n# with the same exit status as the command, 0 in this case.\ntimeout 20 sleep 1\n\n# Send the INT signal after 5s to the 'sleep' command.  Returns after\n# 5 seconds with exit status 124 to indicate the sending of the signal.\ntimeout -s INT 5 sleep 20\n\n# Likewise, but the command ignoring the INT signal due to being started\n# via 'env --ignore-signal'.  Thus, 'sleep' terminates regularly after\n# the full 20 seconds, still 'timeout' returns with exit status 124.\ntimeout -s INT 5s env --ignore-signal=INT sleep 20\n\n# Likewise, but sending the KILL signal 3 seconds after the initial\n# INT signal.  Hence, 'sleep' is forcefully terminated after about\n# 8 seconds (5+3), and 'timeout' returns with an exit status of 137.\ntimeout -s INT -k 3s 5s env --ignore-signal=INT sleep 20\n"
                }
            ]
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}