Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Thanks!

share|improve this question
add comment

3 Answers

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

share|improve this answer
add comment

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
add comment

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
add comment

Your Answer

 
discard

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