Greetings Monks,
I have a script that opens a blocking socket to a messaging server, in a while(1) loop (it is a backgrounded processs). While the script is running, I want to interrupt the socket read process, say every 1 minute, and write a status message to, say, STDERR (basically I want to monitor the process). Here is how my code looks like this:
use Sys::AlarmCall;
#open socket
#....
&socket_read();
sub alarm_signal {
print STDERR "Received alarm\n";
&socket_read();
};
sub socket_read {
while(1){
alarm_call(60, 'alarm_signal');
my $len = $socket->sysread($line,1024);
#.....
}
}
Although the alarm_signal is executed (not after 60 seconds), I get the:
Deep recursion on subroutine "Sys::AlarmCall::alarm_call" at ... error.
I feel Im not using the alarm properly here. How would you implement a way to interrupt a background process to print a debug
message, periodically ?
I forgot to mention, this elaborate alarm call, is to monitor a messaging server. The socket read, is for the advisory message from the messaging server. Basically I wanted a "watch the watcher" kind of script, hence the interrupt to write a debug message.
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.