Server Fault is a question and answer site for system and network administrators. 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

I have a badly coded infinite looping program that I want to run on the command line - but not forever. I want to use ulimit so if it loops forever, it gets cut off.

I'm trying:

$> bash -c "ulimit -t 1; java myinfloopprogram"

but it's like nothing is happening. What's going on, is my commandline command wrong? myinfloopprogram runs just fine.

I'm running a terminal and the version is Ubuntu 9.10 .

share|improve this question
Unbuntu? Is that the anti-Ubuntu? :) – Cawflands Jan 25 '10 at 22:17
It's not, like, sitting there for a second and then dying is it? Cause I think I might know what the problem is in that case ;-) – Matt Simmons Jan 25 '10 at 22:47
up vote 6 down vote accepted

Is the looping program actually using CPU?

-t is for CPU time, not wall clock time, so if your program is not actually using any CPU time it won't be killed.

share|improve this answer
This is EXACTLY what it was, about two minutes of running = 1 second of CPU time for this program. Thanks! – rlb.usa Jan 25 '10 at 23:28

Maybe try something like this instead:

java myinfloopprogram &
for i in $(seq 1 60); do
    kill -0 $pid >/dev/null || break
    sleep 1
kill -0 $pid >/dev/null || kill -TERM $pid
share|improve this answer

ulimit is probably not what you need. You need some sort of bash timeout feature. There's nothing built into bash, but there are a few scripts floating around to do this. eg

share|improve this answer

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.