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

I am using the following code snippet
#!/usr/local/perl/bin/perl -w $| = 1; push @$x, abc(); sub abc { $x = 1; }
The above code causes segmentation fault. To hand the segmentation fault i added a signal handle below.The code is shown below
#!/usr/local/perl/bin/perl -w $| = 1; push @$x, abc(); sub abc { $x = 1; } $SIG{'SEGV'} = '_my_sig_handler'; sub _my_sig_handler{ print "here"; exit(1); }
The script is able to catch the SEGV signal , but the script doest not exit. I did a truss on the process and think it goes in a infinite loop.

Could you help here ??

Replies are listed 'Best First'.
Re: SEGV Handling , srcipt does not exit after SEGV handling
by dave_the_m (Monsignor) on Jul 08, 2009 at 12:25 UTC
    Once the perl interpreter has SEGV'd, it's in a corrupt and inconsistent state. Attempting to execute Perl code at that point (e.g. in a SEGV signal handler) is just likely to lead to more SEGVs, which may be why you're seeing it go into an infinite loop.

    Dave.

      Yeah i think this is the case, as the truss output shows segment faults recurring, but the thing is i want to capture the stack trace when this segmentation fault occurs.
        If you want a C-level stack trace, then run perl under gdb or similar.

        Dave.

Re: SEGV Handling , srcipt does not exit after SEGV handling
by Anonymous Monk on Jul 08, 2009 at 13:26 UTC
Re: SEGV Handling , srcipt does not exit after SEGV handling
by Anonymous Monk on Jul 08, 2009 at 11:40 UTC
    Which perl version? Copy/paste the output of perl -V command into <code></code> tags.
      perl -v This is perl, v5.8.6 built for i86pc-solaris
        Your script is not segfaulting on "perl, v5.8.5 built for sun4-solaris"
        I said perl -V, capital V