0

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!

3 Answers 3

1

You can use the timeout command :

timeout 30s my_command my_args

See man page for details.

1
  • 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, 2010 at 20:41
0

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.

1
  • 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, 2010 at 11:29
0

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

You must log in to answer this question.