Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

so by typing

/.blabla

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

3 Answers 3

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 : http://www.cyberciti.biz/faq/shell-scripting-run-command-under-alarmclock/

share|improve this answer

You could use sleep to accomplish this:

./blabla &
pid=$!
(sleep TIMEOUT; kill $pid 2>/dev/null) &
sleeppid=$!
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

 
discard

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.