See also the sigtrap documentation.
Here's some simple test code to play with:
#!/usr/bin/perl -w # Test code to demonstrate signals. # A file is created, then removed by the signal handler. use strict; use warnings; use sigtrap; use IO::Handle; use sigtrap handler => \&TermHandler, 'normal-signals'; my $mystery = "/tmp/mystery_date.txt"; sub TermHandler { my $signal = shift; print STDERR "TermHandler: $signal signal received at ".localtime( +).".\n"; unlink($mystery) if -f $mystery; die("death"); } # Create file and sleep forever open(OUT, ">>", $mystery) || die("Cannot open $mystery: $!"); autoflush OUT 1; autoflush STDOUT 1; while (1) { print OUT "The time is now ".localtime()."\n"; print "The time is now ".localtime()."\n"; sleep(2); }
In reply to Re: When I am using Ctrl-C and coming out of Perl Program
by gmargo
in thread When I am using Ctrl-C and coming out of Perl Program
by sanPerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |