I have a sysadmin script which is trying to do a network operations on all ports (1-65k). It uses the system function to call a program which takes about 45 seconds to timeout. To make the script finish in my lifetime, I'd like to shorten the timeout. I have something like this:
for ($i = 0; $i <= 65535; $i++) {
print "port $i\n";
system "this takes 45 seconds to timeout";
}
I've noticed that pressing the interrupte sequence (^C) will start a new iteration throught the loop. Is it possibel to send the INT signal to the running program? This doesn't seem to work:
for ($i = 0; $i <= 65535; $i++) {
print "port $i\n";
system "this takes 45 seconds to timeout";
sleep 2;
kill ('INT', $$);
}
I think each instance of system() should result in a new PID. Could this be handled by forking, and sending the INT signal from the parent to the child? I'm just not sure where to go. Any advise is appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.