I don't care much about what ikagami said exactly, but you did kill the program is what he noticed, and that is what I focus on. As far as I'm concerned that is the reason why your example does not print anything. Maybe a piece of code will help:
use strict ; use warnings ; alarm 2 ; $SIG{'ALRM'} = sub{ print "Timeout reached" } ; $SIG{'INT'} = sub { exit(0) } ; <> ; __END__ [/tmp] # perl pltst1.pl ^C[/tmp] # perl pltst1.pl ^CTimeout reached[/tmp] # (1. ctrl-c pressed < 2 seconds 2. ctrl-c pressed > 2 seconds)
1. So you see, it does matter if you kill the program. 2. Whether something is being outputted to STDOUT is not a secondary issue. It matters everything. STDERR and STDOUT buffer mechanisms are fundamentaly different.
edit: So if people are down-voting this that is fine, but then at least show me where I am wrong please.
edit 2: Examples added regards the difference between STDOUT and STDERR below (Pevious example was Linux, this was on Windows):
WITH syswrite STDERR and print STDERR:
use strict ; use warnings ; alarm 2 ; $SIG{ALRM} = sub{ syswrite STDERR, "s Timeout reached " ; print STDERR "p Timeout reached " ; } ; sleep(4) ; syswrite STDERR, "s Program end " ; print STDERR "p Program end " ; sleep(2) ; __END__ C:\perlproject>perl sigtst.pl s Timeout reached p Timeout reached s Program end p Program end s Timeout reached - Printed after 2 seconds p Timeout reached - Printed after 2 seconds s Program end - Printed after 4 seconds p Program end - Printed after 4 seconds
WITH syswrite STDOUT and print STDOUT:
use strict ; use warnings ; alarm 2 ; $SIG{ALRM} = sub{ syswrite STDOUT, "s Timeout reached " ; print STDOUT "p Timeout reached " ; } ; sleep(4) ; syswrite STDOUT, "s Program end " ; print STDOUT "p Program end " ; sleep(2) ; __END__ C:\perlproject>perl sigtst.pl s Timeout reached s Program end p Timeout reached p Program end s Timeout reached - Printed after 2 seconds s Program end - Printed after 4 seconds p Timeout reached - Printed after 6 seconds p Program end - Printed after 6 seconds
In reply to Re^13: Print inside SIGNALS
by Veltro
in thread Print inside SIGNALS
by pedrete
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |