Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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'm writing a script that runs many simultaneous processes that run the "dig" command. Once in a while (relatively rare, but happens in every run since I run dig many times) the dig command hangs with 0% CPU. Therefore, my script never terminates. I've created a monitor process for each dig command I run, which terminates it after a while, but I was wondering if there isn't a simpler and more efficient way to run a process with a pre-determined "expiration date", i.e. if the process runs more then X seconds it gets a signal that terminates it.


share|improve this question

You can use the timeout command :

timeout 30s my_command my_args

See man page for details.

share|improve this answer
Thanks! This is exactly what I was looking for! P.S. I would vote the answer up, but I don't have enough reputation points. I'm new in town...:) – Yoav Mar 17 '10 at 20:41

The question is why is your dig process hanging the first place. Try running it under some debug tools like ltrace and strace, or even under ddd and see why it's hanging. If you find anything unusual post it as bug, it's the only way open source software gets better.

Dig should time out , however something may be broken on your network.

share|improve this answer
The hung processes are waiting on sigsuspend(). kill -SIGIO <pid> releases them causing them to terminate. I'm not sure why they get there, but it might be related to too many digs running at the same time. – Yoav Mar 17 '10 at 11:29

you can also try the timeout options dig has, eg +time=T , +tries=Tetc. see thedig` man page for more

share|improve this answer

Your Answer


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