timeout
Processes and system
Usage
timeout <duration> <command>Runs a command under a time limit and cuts it off when the limit passes, exiting 124; the default signal is TERM, which a hung program can ignore, so add `-k` to follow with KILL (GNU coreutils, absent on macOS).
Common flags
| Flag | Meaning |
|---|---|
| 30 / 5m / 1h | Duration in seconds unless you add s, m, h or d. |
| -s <SIGNAL> | Send something other than TERM when time runs out. |
| -k 5 | If the command ignores TERM, send KILL five seconds later. |
| --preserve-status | Exit with the command's own status instead of 124. |
| exit code 124 | What timeout returns when it had to stop the command. |
Examples
timeout 30 curl -s https://example.comGive up on a hung request after thirty seconds.
timeout -k 5 60 ./import.shOne minute to finish politely, then five seconds before KILL.
What is running and what is eating the machine. Identifying it comes before killing it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does timeout do?
Runs a command under a time limit and cuts it off when the limit passes, exiting 124; the default signal is TERM, which a hung program can ignore, so add `-k` to follow with KILL (GNU coreutils, absent on macOS).
Q. How do I type it?
timeout <duration> <command> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man timeout. This command sits under Processes and system.
Related commands
man page: man timeout