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

Hi Monks,

I have a Perl program which is part of batch job. This looks like below

#!/usr/bin/perl # # runModule.pl # Run a DexNet module in the Integreation Environment # Usage: ./runModule.pl PROPERTY_FILE # Create the property file to mimic PTM/PTM_205_Properties.txt use lib ('/home/matlab/Build/Scheduler/Perl/lib'); use DBI; use Util::Scheduler; use Util::Runner; use Symbol; eval { die "Usage: $0 [SQL_SERVER_PROPERTIES_FILE] [APPLICATION_ID] [APPL +ICATION_NAME]\n" unless $ARGV[2]; my $properties_file = $ARGV[0]; my $id = $ARGV[1]; my $name = $ARGV[2]; my $ADNET = Util::Helper->readPropertiesFromFile($properties_file) +; my $properties = Util::Helper->readPropertiesFromDatabase($ADNET, +$id); my $runner = Util::Runner->new($ADNET, $id, $name); my $wait_timeout = $properties->{'wait.timeout'}; my $lock_timeout = $properties->{'lock.timeout'}; Util::Scheduler->begin($ADNET, $id, $wait_timeout, $lock_timeout); $runner->initialize; $runner->runAll; Util::Scheduler->end($ADNET, $id); }; if ($@) { exit(1); } else { exit(0); }

This program in turn execute a set of SQL code stored in a form of stored procedure.

The problem is sometime the program fails and throws a Segmentation fault like below.

78481 Segmentation fault (core dumped) perl runScheduledModule.pl ~/Run/conf/adnet.db.properties $1 "$2

Could you please suggest us a possible ways to overcome such issue to occur in recurring basis.

Replies are listed 'Best First'.
Re: Segmentattion fault
by tobyink (Canon) on Nov 04, 2014 at 09:13 UTC

    It is pretty difficult to trigger a segfault using pure Perl code.

    my $a = []; my $b = [$a]; push @$a, $b; 1~~$a; # though it is possible

    The chances are that your segfault is happening in one of the modules you're loading. Specifically one of them that has been written in C rather than pure Perl. Most DBI drivers are at least partly written in C. These Util::* modules don't appear to be any publicly available modules, so I haven't got a clue what they're doing. The problem may well occur in one of them.

Re: Segmentattion fault
by QM (Parson) on Nov 04, 2014 at 11:22 UTC
    Try using the debugger to step through the code (assuming the debugger doesn't "fix" the problem). Or sprinkle print statements liberally.

    One of my quick and dirty methods is to print the file and line number after each executable line:

    $x = 14; print STDERR __FILE__ . ':' . __LINE__ . "\n";

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of