O'Reilly logo

Nagios, 2nd Edition by Wolfgang Barth

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

25.4 Implementing Timeouts

To implement a hard timeout, the function alarm() is available in C, Perl, and other programming languages, which normally calls the system functon of the same name (see man 2 alarm). For the Perl alarm() function, the timeout is specified in seconds:

# ... GetOptions ...
alarm($timeout);
# ... core code ...
alarm(0);
# ... end

The alarm($timeout) call starts the alarm function, the argument 0 for the second call stops it again. The first call should be used before time-intensive processing steps, in network-based plugins before opening sockets, and similar situations where a long delay may occur. A good place is after the command line has been processed via GetOptions.

At the end of the plugin it is recommended that you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required