Linux command
timeout 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run a command with a time limit
timeout 30s [command]
Run with time limit
timeout 5m [command]
Send specific signal
timeout --signal=SIGKILL 10s [command]
Kill after additional time
timeout --kill-after=10s 30s [command]
Preserve exit status
timeout --preserve-status 5s [command]
Run with timeout
timeout --foreground 30s [command]
说明
timeout runs a command with a specified time limit. If the command does not complete within the duration, timeout sends a signal (SIGTERM by default) to terminate it. Part of GNU coreutils. The default signal (SIGTERM) allows processes to clean up before exiting. For processes that ignore SIGTERM, use --kill-after to send SIGKILL after an additional grace period. Exit status is 124 if the command times out, 137 if killed by SIGKILL, or the command's own exit status if it completes within the limit. Use --preserve-status to return the signal number + 128 on timeout.
参数
- -k _duration_, --kill-after=_duration_
- Send SIGKILL after additional duration if command still running
- -s _signal_, --signal=_signal_
- Signal to send on timeout (default: SIGTERM)
- --preserve-status
- Return command's exit status even on timeout
- --foreground
- Don't create new process group (for terminal interaction)
- -v, --verbose
- Diagnose signal sent to stderr
FAQ
What is the timeout command used for?
timeout runs a command with a specified time limit. If the command does not complete within the duration, timeout sends a signal (SIGTERM by default) to terminate it. Part of GNU coreutils. The default signal (SIGTERM) allows processes to clean up before exiting. For processes that ignore SIGTERM, use --kill-after to send SIGKILL after an additional grace period. Exit status is 124 if the command times out, 137 if killed by SIGKILL, or the command's own exit status if it completes within the limit. Use --preserve-status to return the signal number + 128 on timeout.
How do I run a basic timeout example?
Run `timeout 30s [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -k _duration_, --kill-after=_duration_ do in timeout?
Send SIGKILL after additional duration if command still running