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");