MCE::Signal - Temporary directory creation/cleanup and signal handling
This document describes MCE::Signal version 1.522
use MCE::Signal qw( [-keep_tmp_dir] [-use_dev_shm] ); use MCE; ## MCE loads MCE::Signal when not present. ## Include MCE::Signal first for options to take effect.
This package configures $SIG{HUP,INT,PIPE,QUIT,TERM,XCPU,XFSZ} to point to stop_and_exit and creates a temporary directory. The main process and workers receiving said signals call stop_and_exit, which signals all workers to terminate, removes the temporary directory unless -keep_tmp_dir is specified, and terminates itself.
The location of the temp directory resides under $ENV{TEMP} if defined, otherwise /dev/shm if writeable and -use_dev_shm is specified, or /tmp.
The temp dir resides under $ENV{TEMP}/mce/ for native Perl on Microsoft Windows.
As of MCE 1.405, MCE::Signal no longer calls setpgrp by default. Pass the -setpgrp option to MCE::Signal to call setpgrp.
## Running MCE through Daemon::Control requires setpgrp to be called ## for MCE releases 1.511 and below. use MCE::Signal qw(-setpgrp); ## Not necessary for MCE 1.512 and above use MCE;
The following are available arguments and their meanings.
-keep_tmp_dir - The temporary directory is not removed during exiting A message is displayed with the location afterwards -use_dev_shm - Create the temporary directory under /dev/shm -no_sigmsg - Do not display a message when receiving a signal -no_kill9 - Do not kill -9 after receiving a signal to terminate -setpgrp - Calls setpgrp to set the process group for the process This option ensures all workers terminate when reading STDIN for MCE releases 1.511 and below. cat big_input_file | ./mce_script.pl | head -10 This works fine without the -setpgrp option: ./mce_script.pl < big_input_file | head -10
Nothing is exported by default. Exportable are 1 variable and 2 subroutines.
$tmp_dir - Path to the temporary directory. stop_and_exit - Described below sys_cmd - Described below
Stops execution, removes temp directory, and exits the entire application. Pass 'TERM' to terminate a spawned or running MCE state.
MCE::Signal::stop_and_exit(1); MCE::Signal::stop_and_exit('TERM');
The system function in Perl ignores SIGNINT and SIGQUIT. These 2 signals are sent to the command being executed via system() but not back to the underlying Perl script. For this reason, sys_cmd was added to MCE::Signal.
## Execute command and return the actual exit status. The perl script ## is also signaled if command caught SIGINT or SIGQUIT. use MCE::Signal qw(sys_cmd); ## Include before MCE use MCE; my $exit_status = sys_cmd($command);
## Creates tmp_dir under $ENV{TEMP} if defined, otherwise /tmp use MCE::Signal; use MCE::Signal qw( :all ); ## Attempt to create tmp_dir under /dev/shm if writable use MCE::Signal qw( -use_dev_shm ); ## Keep tmp_dir after script terminates use MCE::Signal qw( -keep_tmp_dir ); use MCE::Signal qw( -use_dev_shm -keep_tmp_dir );
MCE
Mario E. Roy, <marioeroy AT gmail DOT com>
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install MCE, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MCE
CPAN shell
perl -MCPAN -e shell install MCE
For more information on module installation, please visit the detailed CPAN module installation guide.