Perl Signal Handling

Signal handling in Perl is one of the latest in many things I have had to learn recently. When I started looking for information on this, I of course began by googling for it first, and then resorting the Other Bible before going down some path. However in this case I found many examples where they simply assigned a signal handler for each signal they want to change from their default behavior:

sub INT_handler {
   print("Don't Interrupt!n");
}
 
$SIG{'INT'} = 'INT_handler';

I found this to be quite cumbersome, especially if you are trying to handle multiple signals (in my case almost all possible signals because I need to cleanup lock file). After digging deeper, I came across sigtrap, which allows you to assign handling methods to an individual signal or groups of signals.
A Simple Example:

use sigtrap qw{handler sigHandler normal-signals error-signals};
 
sub sigHandler {
   my $sig = shift;
   $sig = defined $sig ? $sig : "????";
   print STDERR "Signal caught: SIG$sig";
}

I would highly recommend you read further into what each of the signal handler classes for sigtrap are (I.E. normal-signals, error-signals and etc). Hopefully if I have some time I’ll try to read through them and expand upon them further here…

Popularity: 3% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Leave a Reply

  • Recent Comments

  • Tags

    AACS Adobe Photoshop Elements 6 Apple Apple Lossless C++ C/C++ CNN Customer Service Dell Digikam DRM Firefox FLAC Fortune Fortune-Widget Fortune File Ghosts I-IV Giga-Byte Google Google Analytics Hack Internet Explorer Kernel Kubuntu Lingo Linksys SPA2102 Linux Mandriva Microsoft Nine Inch Nails OpenSuse Parody PC World Performance Perl Plugin Pre-Installed Linux Quote of the Day Restaurant Software Engineering Ubuntu VOIP Widget Wordpress YouTube
  • Stack Overflow

    Gravatar
    Jason Mock
    591r
    39
  •  

    July 2007
    S M T W T F S
    « Jun   Aug »
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
  • Archives

  • Categories

  • Books I'm Reading

    ISBN: 0385504225 ISBN: 020161622X ISBN: 0596100469 ISBN: 0321344758