bayruds has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using an interrupt signal handler as follows: our @kill_array = (); $sig{INT} = \&quitting . . sub quitting { my $in = shift; my @groups = @kill_array; if ( (defined $groups[0]) && ($groups[0] ne "") ) { print "Exitting\n"; print "@groups\n"; } exit(1) or die; } #End sub I get the following error when I run it, the value of @kill_array is correct: Caught a SIGSEGV at /perl5.6.0/lib/Carp/Heavy.pm line 88 Segmentation fault Can anyone tell me why I get this error? Thanks

Replies are listed 'Best First'.
Re: Interrupt Signal Handler
by Abigail-II (Bishop) on Jul 13, 2003 at 01:48 UTC
    Interrupts in pre-5.8.0 perls are unsafe. They happen at the C-level, and not the Perl-level, meaning they can fire when Perl is half way of executing an "op". Which means that &quitting can be fired when the Perl internals are halfway being modified. But you will be doing things that assume the internals are consistent, valid and in order. Furthermore, you are doing things in your signal handler that causes Perl to do things at the C-level that are unsafe to use, even at the C-level. Allocation of memory is such a thing.

    If you use a signal handler, do as little as possible in the handler, and try to avoid doing any action that requires Perl to allocate memory, or to call functions that are not reentrant.

    This all sounds very low level, and very "out of Perl". And it is. Signals live at the C-level, and you really have to know what's going at the C-level to understand pre-5.8.0 signals.

    You might want to read up on signals in Stevens' Advanced Programming in the UNIX Environment, IMO more useful than any Perl book if you want to understand the interaction between Perl and the underlaying system (the C-level).

    Abigail

      In particluar, the 3rd edition of camel advises against print (pg.413)

      --Bob Niederman, http://bob-n.com
Re: Interrupt Signal Handler
by chromatic (Archbishop) on Jul 13, 2003 at 01:23 UTC

    I can't be sure how you're using Carp, but I remember it being a little buggy in Perl 5.6.0. Upgrading to 5.6.1 ought to fix that issue, if it's what I think it is. Can you post the code that uses Carp as well as the version of Perl?

      Hi chromatic, I donot use Carp modules's functions anywhere in my program. But I do use die and exit. Can it be because of that? Thanks