timeout flags & options
Basic usage
Kill a command after a duration. Supports s, m, h, d suffixes.
timeout 10s ping example.com
timeout 5m ./long_script.sh
-s, --signal
Send a specific signal instead of SIGTERM.
timeout -s SIGKILL 30s ./process
timeout -s 9 10s ./stubborn_process
-k, --kill-after
If the process doesn't stop after the initial signal, send SIGKILL after this duration.
timeout -k 5s 30s ./process
--preserve-status
Exit with the same status as the command, even if it timed out.
timeout --preserve-status 10s ./test.sh
--foreground
Don't create a background process group. Useful when timeout is not the direct child of the shell.
timeout --foreground 60s ./interactive_script.sh
Check if command timed out
timeout exits with status 124 if the command timed out.
timeout 5s sleep 10; [ $? -eq 124 ] && echo "Timed out"
Common patterns
timeout 30s curl -o file.zip https://example.com/file.zip
timeout 2m make -j4