Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- how to limit system() execution time?
May 23, 2005, 2:50 am
rate this thread
I'm shelling out to a unreliable 3rd party utility that
is supposed to spit some stuff out to STDOUT and exit.
It always spits out the right data but sometimes it just
doesn't exit properly and the system() call is left
is there any easy way (through threads perhaps?) of
giving the system() call say 10 seconds to do it's thing,
capturing the STDOUT as usual, but then killing it off if
it hasn't exited?
Re: how to limit system() execution time?
On Mon, 23 May 2005 05:21:25 GMT, Jürgen Exner said:
Hmm. The first thing that occurred to me was "Do the fork()
and exec() manually, capture the pid of the child, kill it
in a SIGALRM handler."
Interestingly, the FAQ your refer to itself refers to perlipc,
which in turn talks about SIGALRM being caught in an eval block,
If the operation being timed out is system() or qx(), this technique is
liable to generate zombies. If this matters to you, you'll need to
do your own fork() and exec(), and kill the errant child process.
Now I don't know if zombies matter to the OP, nor do I quite
understand how he is capturing STDOUT using system rather than,
for instance qx// or open.
Anyhow, I'd suggest the OP look at the "Safe Pipe Opens" section
in perlipc, look at the various examples and consider setting a
SIGALRM handler and calling alarm(10) at the appropriate place.