Executing non-reentrant code in signal handlers is 
dangerous at best.  There are many write-ups on this.

----
Steve Sapovits
Global Sports Interactive
Work Email: [EMAIL PROTECTED]
Home Email: [EMAIL PROTECTED]
Work Phone: 610-491-7087
Cell:       610-574-7706
Pager:      877-239-4003

> -----Original Message-----
> From: Roger Grayson [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, March 05, 2002 2:53 PM
> To:   Kelly Robbins
> Cc:   [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject:      Re: Signal to timeout a long running query
> 
> Kelly Robbins wrote:
> > Tim,
> > 
> > This is exactly the example that I used.  I can get the program to run
> for
> > a few iterations, and handle a few timeouts, but it eventually seg
> > faults. :(
> > 
> > I'm including the output generated from print statements in my script.
> It
> > shows a few iterations, a few timeouts, then a seg fault.  I can get the
> > signal to work, but the seg fault over time is what I'm concerned about.
> > Any suggestions for this?
> > 
> > At CheckTNSPing
> > At CheckDiskSpace
> > Timeout while performing DiskSpace alert
> > Sleeping for 5 seconds starting @ 2002/03/05 17:01:47.
> > At CheckTNSPing
> > At CheckDiskSpace
> > At CheckSessionInfo
> > At CheckInvalidRows
> > At CheckPermissions
> > Timeout while performing Permissions alert
> > Sleeping for 5 seconds starting @ 2002/03/05 17:02:08.
> > At CheckTNSPing
> > At CheckDiskSpace
> > Timeout while performing DiskSpace alert
> > Sleeping for 5 seconds starting @ 2002/03/05 17:02:22.
> > At CheckTNSPing
> > At CheckDiskSpace
> > At CheckSessionInfo
> > At CheckInvalidRows
> > At CheckPermissions
> > At CheckMaxParameters
> > At CheckObjectExtents
> > Timeout while performing ObjectExtents alert
> > Sleeping for 5 seconds starting @ 2002/03/05 17:02:43.
> > At CheckTNSPing
> > At CheckDiskSpace
> > zsh: 11968 segmentation fault  /usr/local/bin/perl5
> > /usr/vendor/oracle/UU-DBA/cr
> > on/../bin/OracleMonitor  -s
> > 
> > 
> >
> --------------------------------------------------------------------------
> ---
> > Kelly Robbins
> > Database Administrator, Internet Computing Systems
> > WorldCom
> > 880 Technology Dr., Ann Arbor MI 48108
> > E-mail: [EMAIL PROTECTED]
> > Phone: (734) 214-5922
> > Fax: (734) 214-7310
> >
> --------------------------------------------------------------------------
> --
> > 
> > On Tue, 5 Mar 2002 [EMAIL PROTECTED] wrote:
> > 
> > 
> >>Kelly,
> >>
> >>I think that what you want to achieve can be done with the alarm()
> function.
> >>If you use it in an eval block, it won't kill the program. Here's a
> simple
> >>example (from "Perl: The Complete Reference" by Martin Brown, pg 455):
> >>
> >>  print "Your name is? :\n";
> >>  eval
> >>   {
> >>      local $SIG{ALRM} = sub { die "Timeout" };
> >>      alarm(10);
> >>    $name = <STDIN>;
> >>    chomp $name;
> >>    alarm 0;
> >>   };
> >>
> >>   if ($@ and $@ =~ /Timeout/) { $name = 'Anonymous' }
> >>   print "Hello $name!\n";
> >>
> >>alarm(10) sets the alarm for 10 seconds. alarm(0) turns it off. The
> special
> >>variable $@ aka $EVAL_ERROR will be empty if the eval execute without
> error,
> >>otherwise it holds the "die" message.
> >>
> >>There is also a good discussion of this stuff in the O'Reilly book
> >>"Programming Perl".
> >>
> >>Hope this helps,
> >>
> >>Tim Helck
> >>
> >>-----Original Message-----
> >>From: Kelly Robbins [mailto:[EMAIL PROTECTED]]
> >>Sent: Tuesday, March 05, 2002 12:17 PM
> >>To: [EMAIL PROTECTED]
> >>Subject: Signal to timeout a long running query
> >>
> >>
> >>
> >>I'm trying to incorporate a signal in a database monitoring tool that we
> >>have written which runs "forever".  I would like to be able to break out
> >>of a long running query, but I would also like the script to continue
> >>running.
> >>
> >>I have been successful writing a signal to quit a query that is running
> to
> >>long, and the script will then continue, but the script eventually seg
> >>faults over time.  Is there any way to prevent the seg faults?  If not,
> is
> >>there a better way of imposing a timeout on my queries?
> >>
> >>Kelly
> >>
> >>
> >>
> > 
> 
> Kelly,
> 
> How much work is your signal handler doing? Lincoln mentions in "Network
> Programming with Perl" that 
> sig handlers can cause segfaults if you do a lot of work in them. So if
> you are doing more than just 
> calling die() or setting a global var in your sig handler that could be
> the problem. It might also 
> matter which version of perl you are using.
> 
> Roger
> 
> -- 
> There are lies, there are damned lies, and there are the power point
> presentations you make up to 
> explain your code.

Reply via email to