BOOL WINAPI win32_ctrlhandler(DWORD dwCtrlType) ... switch(dwCtrlType) { case CTRL_CLOSE_EVENT: /* A signal that the system sends to all processes attached to a console when the user closes the console (either by choosing the Close command from the console window's System menu, or by choosing the End Task command from the Task List */ if (do_raise(aTHX_ 1)) /* SIGHUP */ sig_terminate(aTHX_ 1); return TRUE; #### use strict; use warnings; use Config; BEGIN { open(LOG,">","what_happens.log") or die "$!"; my $ofh = select LOG; $|=1; select $ofh; print LOG "Unbuffered Log\n"; } sub pout { print {$_} @_,"\n" for (*LOG, *STDERR); } END { pout("end handler called"); close LOG; } pout "Started"; my $signum = 0; foreach my $signame (split(' ', $Config{sig_name})) { if ($signum) { pout("Establishing $signame $signum"); $SIG{$signame} = $signame =~ /^KILL|STOP$/ ? 'IGNORE' # According to perldoc perlipc, they can be ignored, but not trapped : sub { $SIG{$signame} = 'DEFAULT'; pout("Murdered by signal $signame, default handler established"); if ($signame eq 'INT') { pout("This seems to be Keyboard interrupt"); exit; } else { pout("Suicide"); kill($signum, $$); # proceed with normal handling of signal } }; } ++$signum; } pout("Interrupt handlers registered"); sleep(6); pout("Normal exit");