[Nagiosplug-devel] perl signal handling

Stanley Hopcroft Stanley.Hopcroft at IPAustralia.Gov.AU
Mon Jul 26 18:17:10 CEST 2004


Dear Sir,

I am writing to thank you for your letter and say,

On Mon, Jul 26, 2004 at 08:19:47AM -0700, Jason Martin wrote:
> I've got a perl plugin that invokes df.  I've noticed that if there is a stale NFS mount the df command will hang
> forever and NRPE will kill the plugin, but the df lives on.

> What is the appropriate way to make sure that the underlying df is 
> killed along with the plugin?

that since almost certainly df is invoked by popen (eg open DF, 'df |' 
or `df` in Perl), df will be seperately scheduled and therefore 
an independent process (not related to both your plugin and NRPE).

Your plugin should timeout the df command (or any other command that can 
hang) with eval and a $SIG{ALRM}.

See perldoc perlipc section on Signals ('timeouts in Unix')

'Here's an example:

           eval {
               local $SIG{ALRM} = sub { die "alarm clock restart" };
               alarm 10;
               flock(FH, 2);   # blocking write lock
               alarm 0;
           };
           if ($@ and $@ !~ /alarm clock restart/) { die }

'

You need to read the rest because your Perl code, if it is interrupted 
by the alarm signal (timeout), will have to kill the df process in such 
a way as to avoid zombies.


> Thanks,
> -Jason Martin
> -- 
> Shift happpens. - Doppler
(ROFL).


Yours sincerely


-- 
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------

'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'

from Meditation 17, J Donne.




More information about the Devel mailing list