alex5161 has asked for the wisdom of the Perl Monks concerning the following question:
First time trying to work with signals in Perl.
Reviewing example I try it, but not able to get it work for 'exit'.
I hope, I am correct, assuming, that the ending any code by
the $SIG{EXIT} should be de-referenced and processed?!
So, I have such code, that, I assume, should, but does not process signal handling:
#!/bin/perl sub trp_h{ print "\nIn 'trp_h()'. ". "\nReceived parameters \@_: ".(join ", ",@_). "\n\$! as a number: ".($!+0).", as a string: ".(" ".$!). "\n now 'sleep 5' before return."; sleep 5; } $SIG{EXIT}='trp_h'; print "\nSet handler: $SIG{EXIT}\n"; exit(5); print "after first exit"; $SIG{EXIT}=\&trp_h; print "\nSet handler to code: $SIG{EXIT}\n"; exit(3); print "after second exit\n"; print "Restoring to default\n"; $SIG{EXIT}='DEFAULT'; exit(2); exit 1;
Please, help me understand what is wrong, or,
if I mistaken on assumption that the 'exit()' is processed by the $SIG{EXIT},
how it could be handled to process activity, such as in UNIX 'trap "..." EXIT' command?
Thanks!
|
---|