Hello PerlMonk.
I have console perl program that connects to database, checking records every 30 seconds, and if data has changed it should do it's job. With ctrl + c, I want this program to disconnect from database, so I tried SIGINT signal handler even though Chapter 4 of "Advanced Perl Programming" warned me the trouble of Win32 signal. My program shows no response to ctrl + c while sleeping 30 seconds and this is my problem.
So far, I have read through previous threads,
SOLVED Perl SIG INT handling conundrum.
,
GOTO, Signals and Win32
, and especially this one
win32, ctrl-c, sleep, and signals
.
"set PERL_SIGNALS=unsafe" gives me quick response but it yields fatal error dialog saying perl has crashed. I am using perl 5.12.1 of Win32 IndigoAMPP package. Below is my sample code.
use strict;
use warnings;
#this doesn't work
#$ENV{PERL_SIGNALS} = "unsafe";
local $SIG{INT} =sub {
print "in SIGINT ...exitting\n";
#here I want disconnect from database;
exit;
};
while (1){
print "in while loop\n";
sleep 30;
#this is what I can do best so far...
#sleep 3 for (0 .. 10);
}
I am glad with any advice.
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.