Sys::RunUntil - make sure script only runs for the given time
This documentation describes version 0.05.
use Sys::RunUntil '30mW';
# code which may only take 30 minutes to run
use Sys::RunUntil '30sC';
# code which may only take 30 seconds of CPU time
Provide a simple way to make sure the script from which this module is loaded, is running only for either the given wallclock time or a maximum amount of CPU time.
There are no methods.
The maximum runtime of the script can be specified in seconds, or with any combination of the following postfixes:
- S seconds
- M minutes
- H hours
- D days
The string "1H30M" would therefor indicate a runtime of 5400 seconds.
The letter C indicates that the runtime is specified in CPU seconds used. The (optional) letter W indicates that the runtime is specified in wallclock time.
The functionality of this module basically depends on alarm and fork, with some pipes and selects mixed in when checking for CPU time.
When the "import" class method is called (which happens automatically with use), that method forks the process and sets an alarm in the parent process and waits for the child process to return. If the process returns before the alarm is activated, that's ok. If the alarm is triggered, it means that the child process is taking to long: the parent process will then kill the child by sending it a TERM (15) signal and exit.
When the "import" class method is called (which happens automatically with use), that method creates a pipe and forks the process. In the child process a signal handler is installed on the INFO (29) signal which prints the total CPU time used on the pipe to the parent. The parent then waits for the minimum amount of time that would need to expire before the CPU limit in the child process is reached. It then sends the INFO signal to the child process to obtain the amount of CPU used by the child. The parent then decides to wait longer or to kill the child process by sending it a TERM (15) signal.
Copyright (c) 2005, 2012 Elizabeth Mattijsen <firstname.lastname@example.org>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Sys::RunUntil, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.