in reply to Segmentation Fault

I don't know why you are getting segfaults when you run your code (and right now I lack the necessary tuits to download it and find out). Your description of the problem is good though and I can make a suggestion or two based on that.

The fact that the ping program you need to use doesn't implement timeout is making your program very complicated, because you have to clean up hung child processes. Signals can help you here (though they may be causing you other grief, see next para), try setting the alarm clock to wake them up again. Then kill them. It's morbid, but what can you do?

I don't know why your sleep call doesn't seem to be working, but you can't use it with alarm.

Replies are listed 'Best First'.
Re: Re: Segmentation Fault
by LiTinOveWeedle (Scribe) on Mar 07, 2002 at 12:43 UTC
    THX to virtualsue for this sugestion. I used alarm to simplified my code a lot. But problem is, that just simple using this:

    eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; qx/$string/; alarm 0; }; if ($@ and $@ !~ /alarm clock restart/) { die }

    will genearate zombies as described in docs:

    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.

    Because I need to capture output from command $string I can't use exec() command instead of backticks qx//. So this seems to be litle bit problematic.

    Anybody know? THX

    Li Tin O've Weedle
    mad Tsort's philosopher

      Consider writing a bourne shell script or a small C program that you run from backticks/qx/system in your main Perl program. Inside this subprogram, set the alarm and run your ping. I think that will put the signal handling where it belongs.