timeout

Run a command with a time limit; stop it if it runs too long.

coreutils automation process control scripting

Install

timeout --version

What it does

timeout runs a command and stops it after a specified duration. Useful for scripts and preventing runaway processes.

Quick Start

# Run for 5 seconds
timeout 5 sleep 20

# Run for 2 minutes
timeout 2m ping google.com

Examples

# Kill after 10 seconds
timeout 10 long_running_script.sh

# Send SIGKILL if needed
timeout -s KILL 5 sleep 100

Notes

  • Supports suffixes: s, m, h
  • Can send different signals