A fast and portable timeout command written in POSIX-compliant shell script. Perfect for systems where GNU timeout isn't available or when a minimal dependency solution is preferred.
The timeout.sh script allows you to run any command with a time limit. If the command exceeds the specified duration, it is terminated with a configurable signal (default: SIGTERM). It is a drop-in replacement for GNU timeout, fully implemented in shell script, making it ideal for minimal or embedded environments.
Whether you're scripting automated jobs, running system diagnostics, or managing CI/CD pipelines, timeout provides a simple yet powerful way to manage long-running commands.
- ✅ Fully written in POSIX shell (no external dependencies)
- ⏳ Accepts durations in seconds, minutes, hours, or days (
10,5m,2h,1d) - 🛑 Custom signal support:
--signal=SIGKILL,--signal=SIGTERM, etc. - 💣 Optional hard-kill after grace period via
--kill-after - 📦 Minimal and portable — great for Docker, initramfs, or restricted environments
timeout.sh [OPTIONS] DURATION COMMAND [ARGS]...-s, --signal=SIGNAL— Signal to send to command (default:TERM)-k, --kill-after=DURATION— SendKILLafter this delay if command is still running-h, --help— Show help message
s(seconds),m(minutes),h(hours),d(days)- Default unit is seconds
124— Command timed out125— Invalid usage or internal error126— Command found but cannot be executed127— Command not found- Otherwise — Exit code of the command itself
timeout.sh 10 sleep 5 # Success - finishes before timeout
timeout.sh 5 sleep 10 # Timeout - sleep killed after 5s
timeout.sh -s KILL 10 my_script # Uses SIGKILL instead of SIGTERM
timeout.sh -k 2 10 long_task.sh # Grace period before SIGKILL- POSIX-compliant shell (e.g.,
/bin/sh) - Basic Unix utilities:
expr,sed,whichorcommand -v
Contributions are welcome! To propose enhancements or fixes:
- Fork the repository
- Create a feature branch
- Submit a pull request with a clear description
If you encounter bugs or have feature suggestions, please open an issue.
This project is licensed under the Apache 2.0 License — see the LICENSE file for details.