This past weekend I was working on a software project and needed to kill a job if it didn’t complete in a certain amount of time. The coreutils package ships with the timeout utility which is ideal for doing this. To use timeout you pass it a duration to wait and the command to run:
$ timeout 5 /bin/sleep 60 || echo "Failure"
Failure
In the example above timeout will kill /bin/sleep if it doesn’t complete in 5 seconds. Super handy utility!