Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

so by typing


I launch the program blabla. Is there a way, from the terminal, to stop (i.e. equivalent of ctrl+c) blabla has been running for more than x secs? (I'm trying to test a program of which I have not the source on various random inputs, and the thing gets stuck occasionally).

share|improve this question
up vote 3 down vote accepted

Just use timeout from coreutils package in the repositories:

Installation: sudo apt-get install coreutils

Usage: timeout [-signal] time command

share|improve this answer

Here is a blog post detailing several ways to do that :

share|improve this answer

You could use sleep to accomplish this:

./blabla &
(sleep TIMEOUT; kill $pid 2>/dev/null) &
wait $pid
kill -HUP $sleeppid 2>/dev/null
share|improve this answer
Thanks a lot. It works too, but DoR's link is super elegant.... – user2413 Nov 2 '10 at 20:20
Yes, it's much easier to do with Perl or Python. :) – Kees Cook Nov 2 '10 at 20:22
oh, i meant at the end. There's a C program 'doalarm'. – user2413 Nov 2 '10 at 20:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.