Proc-Background-1.21/0000755000175000017500000000000013560375152015542 5ustar silverdirksilverdirkProc-Background-1.21/lib/0000755000175000017500000000000013560375152016310 5ustar silverdirksilverdirkProc-Background-1.21/lib/Proc/0000755000175000017500000000000013560375152017213 5ustar silverdirksilverdirkProc-Background-1.21/lib/Proc/Background/0000755000175000017500000000000013560375152021272 5ustar silverdirksilverdirkProc-Background-1.21/lib/Proc/Background/Win32.pm0000644000175000017500000001214013560375152022530 0ustar silverdirksilverdirkpackage Proc::Background::Win32; $Proc::Background::Win32::VERSION = '1.21'; # ABSTRACT: Windows-specific implementation of process create/wait/kill require 5.004_04; use strict; use Exporter; use Carp; use Win32::Process qw( NORMAL_PRIORITY_CLASS INFINITE ); use Win32::ShellQuote (); @Proc::Background::Win32::ISA = qw(Exporter); sub _new { my $class = shift; unless (@_ > 0) { confess "Proc::Background::Win32::_new called with insufficient number of arguments"; } return unless defined $_[0]; # If there is only one argument, treat it as system() would and assume # it should be split into arguments. The first argument is then the # application executable. my ($exe, $cmdline); if (@_ == 1) { $cmdline= $_[0]; ($exe) = Win32::ShellQuote::unquote_native($cmdline); } # system() would treat a list of arguments as an un-quoted ARGV # for the program, so concatenate them into a command line appropriate # for Win32 CommandLineToArgvW to decode back to what we started with. # Preserve the first un-quoted argument for use as lpApplicationName. else { $exe = $_[0]; $cmdline= Win32::ShellQuote::quote_native(@_); } # Find the absolute path to the program. If it cannot be found, # then return. To work around a problem where # Win32::Process::Create cannot start a process when the full # pathname has a space in it, convert the full pathname to the # Windows short 8.3 format which contains no spaces. $exe = Proc::Background::_resolve_path($exe) or return; $exe = Win32::GetShortPathName($exe); my $self = bless {}, $class; # Perl 5.004_04 cannot run Win32::Process::Create on a nonexistant # hash key. my $os_obj = 0; # Create the process. if (Win32::Process::Create($os_obj, $exe, $cmdline, 0, NORMAL_PRIORITY_CLASS, '.')) { $self->{_pid} = $os_obj->GetProcessID; $self->{_os_obj} = $os_obj; return $self; } else { return; } } # Reap the child. # (0, exit_value) : sucessfully waited on. # (1, undef) : process already reaped and exit value lost. # (2, undef) : process still running. sub _waitpid { my ($self, $blocking, $wait_seconds) = @_; # Try to wait on the process. my $result = $self->{_os_obj}->Wait($wait_seconds? int($wait_seconds * 1000) : $blocking ? INFINITE : 0); # Process finished. Grab the exit value. if ($result == 1) { my $exit_code; $self->{_os_obj}->GetExitCode($exit_code); if ($exit_code == 256 && $self->{_called_terminateprocess}) { return (0, 9); # simulate SIGKILL exit status } else { return (0, $exit_code<<8); } } # Process still running. elsif ($result == 0) { return (2, 0); } # If we reach here, then something odd happened. return (0, 1<<8); } sub _die { my $self = shift; my @kill_sequence= @_ && ref $_[0] eq 'ARRAY'? @{ $_[0] } : qw( TERM 2 TERM 8 KILL 3 KILL 7 ); # Try the kill the process several times. # _reap will collect the exit status of the program. while (@kill_sequence and $self->alive) { my $sig= shift @kill_sequence; my $delay= shift @kill_sequence; $sig eq 'KILL'? $self->_send_sigkill : $self->_send_sigterm; last if $self->_reap(1, $delay); # block before sending next signal } } # Use taskkill.exe as a sort of graceful SIGTERM substitute. sub _send_sigterm { my $self = shift; # TODO: This doesn't work reliably. Disabled for now, and continue to be heavy-handed # using TerminateProcess. The right solution would either be to do more elaborate setup # to make sure the correct taskkill.exe is used (and available), or to dig much deeper # into Win32 API to enumerate windows or threads and send WM_QUIT, or whatever other APIs # processes might be watching on Windows. That should probably be its own module. # my $pid= $self->{_pid}; # my $out= `taskkill.exe /PID $pid`; # If can't run taskkill, fall back to TerminateProcess # $? == 0 or $self->_send_sigkill; } # Win32 equivalent of SIGKILL is TerminateProcess() sub _send_sigkill { my $self = shift; $self->{_os_obj}->Kill(256); # call TerminateProcess, essentially SIGKILL $self->{_called_terminateprocess} = 1; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Proc::Background::Win32 - Windows-specific implementation of process create/wait/kill =head1 VERSION version 1.21 =head1 SYNOPSIS Do not use this module directly. =head1 DESCRIPTION This is a process management class designed specifically for Win32 operating systems. It is not meant used except through the I class. See L for more information. =head1 NAME Proc::Background::Win32 - Interface to process management on Win32 systems =head1 IMPLEMENTATION This package uses the Win32::Process class to manage the objects. =head1 AUTHORS =over 4 =item * Blair Zajac =item * Michael Conrad =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2019 by Michael Conrad, (C) 1998-2009 by Blair Zajac. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Proc-Background-1.21/lib/Proc/Background/Unix.pm0000644000175000017500000000772113560375152022562 0ustar silverdirksilverdirkpackage Proc::Background::Unix; $Proc::Background::Unix::VERSION = '1.21'; # ABSTRACT: Unix-specific implementation of process create/wait/kill require 5.004_04; use strict; use Exporter; use Carp; use POSIX qw(:errno_h :sys_wait_h); @Proc::Background::Unix::ISA = qw(Exporter); # Start the background process. If it is started sucessfully, then record # the process id in $self->{_os_obj}. sub _new { my $class = shift; unless (@_ > 0) { confess "Proc::Background::Unix::_new called with insufficient number of arguments"; } return unless defined $_[0]; # If there is only one element in the @_ array, then it may be a # command to be passed to the shell and should not be checked, in # case the command sets environmental variables in the beginning, # i.e. 'VAR=arg ls -l'. If there is more than one element in the # array, then check that the first element is a valid executable # that can be found through the PATH and find the absolute path to # the executable. If the executable is found, then replace the # first element it with the absolute path. my @args = @_; if (@_ > 1) { $args[0] = Proc::Background::_resolve_path($args[0]) or return; } my $self = bless {}, $class; # Fork a child process. my $pid; { if ($pid = fork()) { # parent $self->{_os_obj} = $pid; $self->{_pid} = $pid; last; } elsif (defined $pid) { # child exec @_ or croak "$0: exec failed: $!\n"; } elsif ($! == EAGAIN) { sleep 5; redo; } else { return; } } $self; } # Wait for the child. # (0, exit_value) : sucessfully waited on. # (1, undef) : process already reaped and exit value lost. # (2, undef) : process still running. sub _waitpid { my ($self, $blocking, $wait_seconds) = @_; { # Try to wait on the process. # Implement the optional timeout with the 'alarm' call. my $result= 0; if ($blocking && $wait_seconds) { require Time::HiRes; local $SIG{ALRM}= sub { die "alarm\n" }; Time::HiRes::alarm($wait_seconds); eval { $result= waitpid($self->{_os_obj}, 0); }; Time::HiRes::alarm(0); } else { $result= waitpid($self->{_os_obj}, $blocking? 0 : WNOHANG); } # Process finished. Grab the exit value. if ($result == $self->{_os_obj}) { return (0, $?); } # Process already reaped. We don't know the exist status. elsif ($result == -1 and $! == ECHILD) { return (1, 0); } # Process still running. elsif ($result == 0) { return (2, 0); } # If we reach here, then waitpid caught a signal, so let's retry it. redo; } return 0; } sub _die { my $self = shift; my @kill_sequence= @_ && ref $_[0] eq 'ARRAY'? @{ $_[0] } : qw( TERM 2 TERM 8 KILL 3 KILL 7 ); # Try to kill the process with different signals. Calling alive() will # collect the exit status of the program. while (@kill_sequence and $self->alive) { my $sig= shift @kill_sequence; my $delay= shift @kill_sequence; kill($sig, $self->{_os_obj}); last if $self->_reap(1, $delay); # block before sending next signal } } 1; __END__ =pod =encoding UTF-8 =head1 NAME Proc::Background::Unix - Unix-specific implementation of process create/wait/kill =head1 VERSION version 1.21 =head1 SYNOPSIS Do not use this module directly. =head1 DESCRIPTION This is a process management class designed specifically for Unix operating systems. It is not meant used except through the I class. See L for more information. =head1 NAME Proc::Background::Unix - Unix interface to process management =head1 AUTHORS =over 4 =item * Blair Zajac =item * Michael Conrad =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2019 by Michael Conrad, (C) 1998-2009 by Blair Zajac. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Proc-Background-1.21/lib/Proc/Background.pm0000644000175000017500000004577513560375152021652 0ustar silverdirksilverdirkpackage Proc::Background; $Proc::Background::VERSION = '1.21'; # ABSTRACT: Generic interface to background process management require 5.004_04; use strict; use Exporter; use Carp; use Cwd; use Scalar::Util; @Proc::Background::ISA = qw(Exporter); @Proc::Background::EXPORT_OK = qw(timeout_system); # Determine if the operating system is Windows. my $is_windows = $^O eq 'MSWin32'; my $weaken_subref = Scalar::Util->can('weaken'); # Set up a regular expression that tests if the path is absolute and # if it has a directory separator in it. Also create a list of file # extensions of append to the programs name to look for the real # executable. my $is_absolute_re; my $has_dir_element_re; my $path_sep; my @extensions = (''); if ($is_windows) { $is_absolute_re = '^(?:(?:[a-zA-Z]:[\\\\/])|(?:[\\\\/]{2}\w+[\\\\/]))'; $has_dir_element_re = "[\\\\/]"; $path_sep = "\\"; push(@extensions, '.exe'); } else { $is_absolute_re = "^/"; $has_dir_element_re = "/"; $path_sep = "/"; } # Make this class a subclass of Proc::Win32 or Proc::Unix. Any # unresolved method calls will go to either of these classes. if ($is_windows) { require Proc::Background::Win32; unshift(@Proc::Background::ISA, 'Proc::Background::Win32'); } else { require Proc::Background::Unix; unshift(@Proc::Background::ISA, 'Proc::Background::Unix'); } # Take either a relative or absolute path to a command and make it an # absolute path. sub _resolve_path { my $command = shift; return unless length $command; # Make the path to the progam absolute if it isn't already. If the # path is not absolute and if the path contains a directory element # separator, then only prepend the current working to it. If the # path is not absolute, then look through the PATH environment to # find the executable. In all cases, look for the programs with any # extensions added to the original path name. my $path; if ($command =~ /$is_absolute_re/o) { foreach my $ext (@extensions) { my $p = "$command$ext"; if (-f $p and -x _) { $path = $p; last; } } unless (defined $path) { warn "$0: no executable program located at $command\n"; } } else { my $cwd = cwd; if ($command =~ /$has_dir_element_re/o) { my $p1 = "$cwd$path_sep$command"; foreach my $ext (@extensions) { my $p2 = "$p1$ext"; if (-f $p2 and -x _) { $path = $p2; last; } } } else { foreach my $dir (split($is_windows ? ';' : ':', $ENV{PATH})) { next unless length $dir; $dir = "$cwd$path_sep$dir" unless $dir =~ /$is_absolute_re/o; my $p1 = "$dir$path_sep$command"; foreach my $ext (@extensions) { my $p2 = "$p1$ext"; if (-f $p2 and -x _) { $path = $p2; last; } } last if defined $path; } } unless (defined $path) { warn "$0: cannot find absolute location of $command\n"; } } $path; } # We want the created object to live in Proc::Background instead of # the OS specific class so that generic method calls can be used. sub new { my $class = shift; my $options; if (@_ and defined $_[0] and UNIVERSAL::isa($_[0], 'HASH')) { $options = shift; } unless (@_ > 0) { confess "Proc::Background::new called with insufficient number of arguments"; } return unless defined $_[0]; my $self = $class->SUPER::_new(@_) or return; # Save the start time of the class. $self->{_start_time} = time; # Handle the specific options. if ($options) { if ($options->{die_upon_destroy}) { $self->{_die_upon_destroy} = 1; # Global destruction can break this feature, because there are no guarantees # on which order object destructors are called. In order to avoid that, need # to run all the ->die methods during END{}, and that requires weak # references which weren't available until 5.8 $weaken_subref->( $Proc::Background::_die_upon_destroy{$self+0}= $self ) if $weaken_subref; # could warn about it for earlier perl... but has been broken for 15 years and # who is still using < 5.8 anyway? } } bless $self, $class; } sub DESTROY { my $self = shift; if ($self->{_die_upon_destroy}) { # During a mainline exit() $? is the prospective exit code from the # parent program. Preserve it across any waitpid() in die() local $?; $self->die; delete $Proc::Background::_die_upon_destroy{$self+0}; } } END { # Child processes need killed before global destruction, else the # Win32::Process objects might get destroyed first. $_->die for grep defined, values %Proc::Background::_die_upon_destroy; %Proc::Background::_die_upon_destroy= (); } # Reap the child. If the first argument is false, then return immediately. # Else, block waiting for the process to exit. If no second argument is # given, wait forever, else wait for that number of seconds. # If the wait was sucessful, then delete # $self->{_os_obj} and set $self->{_exit_value} to the OS specific # class return of _reap. Return 1 if we sucessfully waited, 0 # otherwise. sub _reap { my ($self, $blocking, $wait_seconds) = @_; return 0 unless exists($self->{_os_obj}); # Try to wait on the process. Use the OS dependent wait call using # the Proc::Background::*::waitpid call, which returns one of three # values. # (0, exit_value) : sucessfully waited on. # (1, undef) : process already reaped and exit value lost. # (2, undef) : process still running. my ($result, $exit_value) = $self->_waitpid($blocking, $wait_seconds); if ($result == 0 or $result == 1) { $self->{_exit_value} = defined($exit_value) ? $exit_value : 0; delete $self->{_os_obj}; # Save the end time of the class. $self->{_end_time} = time; return 1; } return 0; } sub alive { my $self = shift; # If $self->{_os_obj} is not set, then the process is definitely # not running. return 0 unless exists($self->{_os_obj}); # If $self->{_exit_value} is set, then the process has already finished. return 0 if exists($self->{_exit_value}); # Try to reap the child. If it doesn't reap, then it's alive. !$self->_reap(0); } sub wait { my ($self, $timeout_seconds) = @_; # If $self->{_exit_value} exists, then we already waited. return $self->{_exit_value} if exists($self->{_exit_value}); # If neither _os_obj or _exit_value are set, then something is wrong. return undef if !exists($self->{_os_obj}); # Otherwise, wait for the process to finish. return $self->_reap(1, $timeout_seconds)? $self->{_exit_value} : undef; } sub die { my $self = shift; # See if the process has already died. return 1 unless $self->alive; croak '->die(@kill_sequence) should have an even number of arguments' if @_ & 1; # Kill the process using the OS specific method. $self->_die(@_? ([ @_ ]) : ()); # See if the process is still alive. !$self->alive; } sub start_time { $_[0]->{_start_time}; } sub exit_code { return undef unless exists $_[0]->{_exit_value}; return $_[0]->{_exit_value} >> 8; } sub exit_signal { return undef unless exists $_[0]->{_exit_value}; return $_[0]->{_exit_value} & 127; } sub end_time { $_[0]->{_end_time}; } sub pid { $_[0]->{_pid}; } sub timeout_system { unless (@_ > 1) { confess "$0: timeout_system passed too few arguments.\n"; } my $timeout = shift; unless ($timeout =~ /^\d+(?:\.\d*)?$/ or $timeout =~ /^\.\d+$/) { confess "$0: timeout_system passed a non-positive number first argument.\n"; } my $proc = Proc::Background->new(@_) or return; my $end_time = $proc->start_time + $timeout; my $delay; while (($delay= ($end_time - time)) > 0 && !defined $proc->exit_code) { $proc->wait($delay); } my $alive = $proc->alive; $proc->die if $alive; if (wantarray) { return ($proc->wait, $alive); } else { return $proc->wait; } } 1; __END__ =pod =encoding UTF-8 =head1 NAME Proc::Background - Generic interface to background process management =head1 VERSION version 1.21 =head1 SYNOPSIS use Proc::Background; timeout_system($seconds, $command, $arg1); timeout_system($seconds, "$command $arg1"); my $proc1 = Proc::Background->new($command, $arg1, $arg2); my $proc2 = Proc::Background->new("$command $arg1 1>&2"); $proc1->alive; $proc1->die; $proc1->wait; my $time1 = $proc1->start_time; my $time2 = $proc1->end_time; # Add an option to kill the process with die when the variable is # DESTROYed. my $opts = {'die_upon_destroy' => 1}; my $proc3 = Proc::Background->new($opts, $command, $arg1, $arg2); $proc3 = undef; =head1 DESCRIPTION This is a generic interface for placing processes in the background on both Unix and Win32 platforms. This module lets you start, kill, wait on, retrieve exit values, and see if background processes still exist. =head1 NAME Proc::Background - Generic interface to Unix and Win32 background process management =head1 METHODS =over 4 =item B [options] I, [I, [I, ...]] =item B [options] 'I [I [I ...]]' This creates a new background process. As exec() or system() may be passed an array with a single single string element containing a command to be passed to the shell or an array with more than one element to be run without calling the shell, B has the same behavior. In certain cases B will attempt to find I on the system and fail if it cannot be found. For Win32 operating systems: The Win32::Process module is always used to spawn background processes on the Win32 platform. This module always takes a single string argument containing the executable's name and any option arguments. In addition, it requires that the absolute path to the executable is also passed to it. If only a single argument is passed to new, then it is split on whitespace into an array and the first element of the split array is used at the executable's name. If multiple arguments are passed to new, then the first element is used as the executable's name. If the executable's name is an absolute path, then new checks to see if the executable exists in the given location or fails otherwise. If the executable's name is not absolute, then the executable is searched for using the PATH environmental variable. The input executable name is always replaced with the absolute path determined by this process. In addition, when searching for the executable, the executable is searched for using the unchanged executable name and if that is not found, then it is checked by appending `.exe' to the name in case the name was passed without the `.exe' suffix. Finally, the argument array is placed back into a single string and passed to Win32::Process::Create. For non-Win32 operating systems, such as Unix: If more than one argument is passed to new, then new assumes that the command will not be passed through the shell and the first argument is the executable's relative or absolute path. If the first argument is an absolute path, then it is checked to see if it exists and can be run, otherwise new fails. If the path is not absolute, then the PATH environmental variable is checked to see if the executable can be found. If the executable cannot be found, then new fails. These steps are taking to prevent exec() from failing after an fork() without the caller of new knowing that something failed. The first argument to B I may be a reference to a hash which contains key/value pairs to modify Proc::Background's behavior. Currently the only key understood by B is I. When this value is set to true, then when the Proc::Background object is being DESTROY'ed for any reason (i.e. the variable goes out of scope) the process is killed via the die() method. If anything fails, then new returns an empty list in a list context, an undefined value in a scalar context, or nothing in a void context. =item B Returns the process ID of the created process. This value is saved even if the process has already finished. =item B Return 1 if the process is still active, 0 otherwise. =item B, B Reliably try to kill the process. Returns 1 if the process no longer exists once B has completed, 0 otherwise. This will also return 1 if the process has already died. C<@kill_sequence> is a list of actions and seconds-to-wait for that action to end the process. The default is C< TERM 2 TERM 8 KILL 3 KILL 7 >. On Unix this sends SIGTERM and SIGKILL; on Windows it just calls TerminateProcess (graceful termination is still a TODO). Note that C on Proc::Background 1.10 and earlier on Unix called a sequence of: ->die( ( HUP => 1 )x5, ( QUIT => 1 )x5, ( INT => 1 )x5, ( KILL => 1 )x5 ); which didn't particularly make a lot of sense, since SIGHUP is open to interpretation, and QUIT is almost always immediately fatal and generates an unneeded coredump. The new default should accomodate programs that acknowledge a second SIGTERM, and give enough time for it to exit on a laggy system while still not holding up the main script too much. =item B $exit= $proc->wait; # blocks forever $exit= $proc->wait($timeout_seconds); # since version 1.20 Wait for the process to exit. Return the exit status of the command as returned by wait() on the system. To get the actual exit value, divide by 256 or right bit shift by 8, regardless of the operating system being used. If the process never existed, this returns undef. This function may be called multiple times even after the process has exited and it will return the same exit status. Since version 1.20, you may pass an optional argument of the number of seconds to wait for the process to exit. This may be fractional, and if it is zero then the wait will be non-blocking. Note that on Unix this is implemented with L before a call to wait(), so it may not be compatible with scripts that use alarm() for other purposes, or systems/perls that resume system calls after a signal. In the event of a timeout, the return will be undef. =item B Returns the exit code of the process, assuming it exited cleanly. Returns C if the process has not exited yet, and 0 if the process exited with a signal (or TerminateProcess). Since 0 is ambiguous, check for C first. =item B Returns the value of the signal the process exited with, assuming it died on a signal. Returns C if it has not exited yet, and 0 if it did not die to a signal. =item B Return the value that the Perl function time() returned when the process was started. =item B Return the value that the Perl function time() returned when the exit status was obtained from the process. =back =head1 FUNCTIONS =over 4 =item B I, I, [I, [I...]] =item B 'I I [I [I...]]' Run a command for I seconds and if the process did not exit, then kill it. While the timeout is implemented using sleep(), this function makes sure that the full I is reached before killing the process. B does not wait for the complete I number of seconds before checking if the process has exited. Rather, it sleeps repeatidly for 1 second and checks to see if the process still exists. In a scalar context, B returns the exit status from the process. In an array context, B returns a two element array, where the first element is the exist status from the process and the second is set to 1 if the process was killed by B or 0 if the process exited by itself. The exit status is the value returned from the wait() call. If the process was killed, then the return value will include the killing of it. To get the actual exit value, divide by 256. If something failed in the creation of the process, the subroutine returns an empty list in a list context, an undefined value in a scalar context, or nothing in a void context. =back =head1 IMPLEMENTATION I comes with two modules, I and I. Currently, on Unix platforms I uses the I class and on Win32 platforms it uses I, which makes use of I. The I assigns to @ISA either I or I, which does the OS dependent work. The OS independent work is done in I. Proc::Background uses two variables to keep track of the process. $self->{_os_obj} contains the operating system object to reference the process. On a Unix systems this is the process id (pid). On Win32, it is an object returned from the I class. When $self->{_os_obj} exists, then the process is running. When the process dies, this is recorded by deleting $self->{_os_obj} and saving the exit value $self->{_exit_value}. Anytime I is called, a waitpid() is called on the process and the return status, if any, is gathered and saved for a call to I. This module does not install a signal handler for SIGCHLD. If for some reason, the user has installed a signal handler for SIGCHLD, then, then when this module calls waitpid(), the failure will be noticed and taken as the exited child, but it won't be able to gather the exit status. In this case, the exit status will be set to 0. =head1 SEE ALSO =over =item L IPC::Run is a much more complete solution for running child processes. It handles dozens of forms of redirection and pipe pumping, and should probably be your first stop for any complex needs. However, also note the very large and slightly alarming list of limitations it lists for Win32. Proc::Background is a much simpler design and should be more reliable for simple needs. =item L If you are running on Win32, this article by helps describe the problem you are up against for passing argument lists: L by Daniel Colascione. This module gives you parsing / quoting per the standard CommandLineToArgvW behavior. But, if you need to pass arguments to be processed by C then you need to do additional work. =back =head1 AUTHORS =over 4 =item * Blair Zajac =item * Michael Conrad =back =head1 CONTRIBUTORS =for stopwords Florian Schlichting Kevin Ryde Salvador Fandiño =over 4 =item * Florian Schlichting =item * Kevin Ryde =item * Salvador Fandiño =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2019 by Michael Conrad, (C) 1998-2009 by Blair Zajac. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Proc-Background-1.21/bin/0000755000175000017500000000000013560375152016312 5ustar silverdirksilverdirkProc-Background-1.21/bin/timed-process.PL0000644000175000017500000000437713560375152021340 0ustar silverdirksilverdirkuse Config; use File::Basename qw(basename dirname); chdir(dirname($0)); ($file = basename($0)) =~ s/\.PL$//; $file =~ s/\.pl$// if ($Config{'osname'} eq 'VMS' or $Config{'osname'} eq 'OS2'); # "case-forgiving" open OUT,">$file" or die "Can't create $file: $!"; chmod(0755, $file); print "Extracting $file (with variable substitutions)\n"; print OUT <<"!GROK!THIS!"; $Config{'startperl'} -w !GROK!THIS! print OUT <<'!NO!SUBS!'; =head1 NAME timed-process - Run background process for limited amount of time =head1 SYNOPSIS timed-process [-e exit_status] timeout command [ [ ...]] =head1 DESCRIPTION This script runs I for a specified amount of time and if it doesn't finish, it kills the process. If I runs and exits before the given timeout, B returns the exit value of I. If I did not exit before I seconds, then B will kill the process and returns an exit value of 255, unless the -e command line option is set, which instructs B to return a different exit value. This allows the user of B to determine if the process ended normally or was killed. =cut use strict; use Proc::Background 1.04 qw(timeout_system); use Getopt::Long; $0 =~ s:.*/::; sub usage { print < [ ...]] This script runs command for a specified amount of time and if it doesn't finish, it kills the process. If command runs and exits before the given timeout, timed-process returns the exit value of command. If command did not exit before timeout seconds, then timed-process will kill the process and returns an exit value of 255, unless the -e command line option is set, which instructs timed-process to return a different exit value. This allows the user of timed-process to determine if the process ended normally or was killed. END exit 1; } my $exit_status = 255; Getopt::Long::Configure('require_order'); GetOptions('exit-status=i', => \$exit_status) or usage; if ($exit_status < 0) { die "$0: exit status value `$exit_status' cannot be negative.\n"; } @ARGV > 1 or usage; my @result = timeout_system(@ARGV); if ($result[1]) { exit $exit_status; } else { exit $result[0] >> 8; } !NO!SUBS! Proc-Background-1.21/Makefile.header0000644000175000017500000000074613560375152020440 0ustar silverdirksilverdirkmy @programs_to_install = qw(timed-process); # Allow us to suppress all program installation with the -n (library only) # option. This is for those that don't want to mess with the configuration # section of this file. use Getopt::Std; use vars qw($opt_n); unless (getopts('n')) { die "Usage: $0 [-n]\n"; } @programs_to_install = () if $opt_n; my %optional_PL_FILES= map {("bin/$_.PL" => "bin/$_")} @programs_to_install; my @optional_EXE_FILES= map {"bin/$_"} @programs_to_install; Proc-Background-1.21/Makefile.PL0000644000175000017500000000363613560375152017524 0ustar silverdirksilverdirk# This Makefile.PL for Proc-Background was generated by # Dist::Zilla::Plugin::MakeMaker::Awesome 0.38. # Don't edit it but the dist.ini and plugins used to construct it. use strict; use warnings; use ExtUtils::MakeMaker; my @programs_to_install = qw(timed-process); # Allow us to suppress all program installation with the -n (library only) # option. This is for those that don't want to mess with the configuration # section of this file. use Getopt::Std; use vars qw($opt_n); unless (getopts('n')) { die "Usage: $0 [-n]\n"; } @programs_to_install = () if $opt_n; my %optional_PL_FILES= map {("bin/$_.PL" => "bin/$_")} @programs_to_install; my @optional_EXE_FILES= map {"bin/$_"} @programs_to_install; my %WriteMakefileArgs = ( "ABSTRACT" => "Run asynchronous child processes under Unix or Windows", "AUTHOR" => "Blair Zajac , Michael Conrad ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Proc-Background", "LICENSE" => "perl", "NAME" => "Proc::Background", "PREREQ_PM" => {}, "VERSION" => "1.21", "test" => { "TESTS" => "t/*.t" } ); %WriteMakefileArgs = ( %WriteMakefileArgs, PL_FILES => { %{$WriteMakefileArgs{PL_FILES}||{}}, %optional_PL_FILES }, EXE_FILES => [ @{$WriteMakefileArgs{EXE_FILES}||[]}, @optional_EXE_FILES ], ); my %FallbackPrereqs = (); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; if ( $^O eq 'MSWin32' ) { $WriteMakefileArgs{PREREQ_PM}{'Win32::Process'} = $FallbackPrereqs{'Win32::Process'} = '0.04'; $WriteMakefileArgs{PREREQ_PM}{'Win32::ShellQuote'} = $FallbackPrereqs{'Win32::ShellQuote'} = '0.003001'; } WriteMakefile(%WriteMakefileArgs); Proc-Background-1.21/weaver.ini0000644000175000017500000000057013560375152017536 0ustar silverdirksilverdirk[@CorePrep] [-SingleEncoding] [Name] [Version] [Region / prelude] [Generic / SYNOPSIS] [Generic / DESCRIPTION] [Generic / OVERVIEW] [Collect / ATTRIBUTES] command = attr [Collect / METHODS] command = method [Collect / FUNCTIONS] command = func [Leftovers] [Region / postlude] [Generic / Thanks] [Authors] [-Transformer] transformer = List [Contributors] [Legal] Proc-Background-1.21/t/0000755000175000017500000000000013560375152016005 5ustar silverdirksilverdirkProc-Background-1.21/t/author-pod-syntax.t0000644000175000017500000000045413560375152021603 0ustar silverdirksilverdirk#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Proc-Background-1.21/t/sleep_exit.pl0000755000175000017500000000050213560375152020503 0ustar silverdirksilverdirkuse strict; $| = 1; my ($sleep, $exit_status) = @ARGV; $sleep = 1 unless defined $sleep; $exit_status = 0 unless defined $exit_status; if ($ENV{VERBOSE}) { print STDERR "$0: sleep $sleep and exit $exit_status.\n"; } sleep $sleep; if ($ENV{VERBOSE}) { print STDERR "$0 now exiting.\n"; } exit $exit_status; Proc-Background-1.21/t/01proc.t0000644000175000017500000001333113560375152017277 0ustar silverdirksilverdirk# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' use strict; use vars qw($loaded); BEGIN { $| = 1; print "1..50\n"; } END {print "not ok 1\n" unless $loaded; } my $ok_count = 1; sub ok { shift or print "not "; print "ok $ok_count\n"; ++$ok_count; } use Proc::Background qw(timeout_system); package EmptySubclass; use Proc::Background; use vars qw(@ISA); @ISA = qw(Proc::Background); package main; # If we got here, then the package being tested was loaded. $loaded = 1; ok(1); # 1 # Find the lib directory. my $lib; foreach my $l (qw(lib ../lib)) { if (-d $l) { $lib = $l; last; } } $lib or die "Cannot find lib directory.\n"; # Find the sleep_exit.pl and timed-process scripts. The sleep_exit.pl # script takes a sleep time and an exit value. timed-process takes a # sleep time and a command to run. my $sleep_exit; my $timed_process; foreach my $dir (qw(. ./bin ./t ../bin ../t Proc-Background/t)) { unless ($sleep_exit) { my $s = "$dir/sleep_exit.pl"; $sleep_exit = $s if -r $s; } unless ($timed_process) { my $t = "$dir/timed-process"; $timed_process = $t if -r $t; } } $sleep_exit or die "Cannot find sleep_exit.pl.\n"; $timed_process or die "Cannot find timed-process.\n"; my @sleep_exit = ($^X, '-w', $sleep_exit); my @timed_process = ($^X, '-w', "-I$lib", $timed_process); # Test the alive and wait returns. my $p1 = EmptySubclass->new(@sleep_exit, 2, 26); ok($p1); # 2 if ($p1) { ok($p1->alive); # 3 sleep 3; ok(!$p1->alive); # 4 ok(($p1->wait >> 8) == 26); # 5 } else { ok(0); # 3 ok(0); # 4 ok(0); # 5 } # Test alive, wait, and die on already dead process. Also pass some # bogus command line options to the program to make sure that the # argument protecting code for Windows does not cause the shell any # confusion. my $p2 = EmptySubclass->new(@sleep_exit, 2, 5, "\t", '"', '\" 10 \\" \\\\"'); ok($p2); # 6 if ($p2) { ok($p2->alive); # 7 ok(($p2->wait >> 8) == 5); # 8 ok($p2->die); # 9 ok(($p2->wait >> 8) == 5); # 10 } else { ok(0); # 7 ok(0); # 8 ok(0); # 9 ok(0); # 10 } # Test die on a live process and collect the exit value. The exit # value should not be 0. my $p3 = EmptySubclass->new(@sleep_exit, 10, 0); ok($p3); # 11 if ($p3) { ok($p3->alive); # 12 sleep 1; ok($p3->die); # 13 ok(!$p3->alive); # 14 ok($p3->wait); # 15 ok($p3->end_time > $p3->start_time); # 16 } else { ok(0); # 12 ok(0); # 13 ok(0); # 14 ok(0); # 15 ok(0); # 16 } # Test the timeout_system function. In the first case, sleep_exit.pl # should exit with 26 before the timeout, and in the other case, it # should be killed and exit with a non-zero status. Do not check the # wait return value when the process is killed, since the return value # is different on Unix and Win32 platforms. my $a = timeout_system(2, @sleep_exit, 0, 26); my @a = timeout_system(2, @sleep_exit, 0, 26); ok($a>>8 == 26); # 17 ok(@a == 2); # 18 ok($a[0]>>8 == 26); # 19 ok($a[1] == 0); # 20 $a = timeout_system(1, @sleep_exit, 4, 0); @a = timeout_system(1, @sleep_exit, 4, 0); ok($a); # 21 ok(@a == 2); # 22 ok($a[0]); # 23 ok($a[1] == 1); # 24 # Test the code to find a program if the path to it is not absolute. my $p4 = EmptySubclass->new(@sleep_exit, 0, 0); ok($p4); # 25 if ($p4) { ok($p4->pid); # 26 sleep 2; ok(!$p4->alive); # 27 ok(($p4->wait >> 8) == 0); # 28 } else { ok(0); # 26 ok(0); # 27 ok(0); # 28 } # Test a command line entered as a single string. my $p5 = EmptySubclass->new("@sleep_exit 2 26"); ok($p5); # 29 if ($p5) { ok($p5->alive); # 30 sleep 3; ok(!$p5->alive); # 31 ok(($p5->wait >> 8) == 26); # 32 } else { ok(0); # 30 ok(0); # 31 ok(0); # 32 } sub System { my $result = system(@_); return ($? >> 8, $? & 127, $? & 128); } # Test the timed-process script. First test a normal exit. my @t_args = ($^X, '-w', "-I$lib", $timed_process); my @result = System(@t_args, '-e', 153, 3, "@sleep_exit 0 237"); ok($result[0] == 237); # 33 ok($result[1] == 0); # 34 ok($result[2] == 0); # 35 @result = System(@t_args, 1, "@sleep_exit 10 27"); ok($result[0] == 255); # 36 ok($result[1] == 0); # 37 ok($result[2] == 0); # 38 @result = System(@t_args, '-e', 153, 1, "@sleep_exit 10 27"); ok($result[0] == 153); # 39 ok($result[1] == 0); # 40 ok($result[2] == 0); # 41 # Test the ability to pass options to Proc::Background::new. my %options; my $p6 = EmptySubclass->new(\%options, @sleep_exit, 0, 43); ok($p6); # 42 if ($p6) { ok(($p6->wait >> 8) == 43); # 43 } else { ok(0); # 43 } # Test to make sure that the process is killed when the # Proc::Background object goes out of scope. $options{die_upon_destroy} = 1; { my $p7 = EmptySubclass->new(\%options, @sleep_exit, 99999, 98); ok($p7); # 44 if ($p7) { my $pid = $p7->pid; ok(defined $pid); # 45 sleep 1; ok(kill(0, $pid) == 1); # 46 $p7 = undef; sleep 1; ok(kill(0, $pid) == 0); # 47 } else { ok(0); # 45 ok(0); # 46 ok(0); # 47 } } # Test wait with a timeout on a process that doesn't exit. my $p8 = EmptySubclass->new(@sleep_exit, 10, 0); ok($p8); # 48 ok($p8 && $p8->alive); # 49 ok($p8 && !defined $p8->wait(1.5)); # 50 $p8->die; Proc-Background-1.21/META.json0000644000175000017500000000251313560375152017164 0ustar silverdirksilverdirk{ "abstract" : "Run asynchronous child processes under Unix or Windows", "author" : [ "Blair Zajac ", "Michael Conrad " ], "dynamic_config" : 1, "generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150001", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Proc-Background", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/nrdvana/perl-proc-background/issues" }, "repository" : { "type" : "git", "url" : "https://github.com/nrdvana/perl-proc-background.git", "web" : "https://github.com/nrdvana/perl-proc-background" } }, "version" : "1.21", "x_contributors" : [ "Florian Schlichting ", "Kevin Ryde ", "Salvador Fandi\u00f1o " ], "x_generated_by_perl" : "v5.20.2", "x_serialization_backend" : "Cpanel::JSON::XS version 3.0115" } Proc-Background-1.21/META.yml0000644000175000017500000000150313560375152017012 0ustar silverdirksilverdirk--- abstract: 'Run asynchronous child processes under Unix or Windows' author: - 'Blair Zajac ' - 'Michael Conrad ' build_requires: {} configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Proc-Background resources: bugtracker: https://github.com/nrdvana/perl-proc-background/issues repository: https://github.com/nrdvana/perl-proc-background.git version: '1.21' x_contributors: - 'Florian Schlichting ' - 'Kevin Ryde ' - 'Salvador Fandiño ' x_generated_by_perl: v5.20.2 x_serialization_backend: 'YAML::Tiny version 1.69' Proc-Background-1.21/MANIFEST0000644000175000017500000000051213560375152016671 0ustar silverdirksilverdirk# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012. Changes LICENSE MANIFEST META.json META.yml Makefile.PL Makefile.header README bin/timed-process.PL dist.ini lib/Proc/Background.pm lib/Proc/Background/Unix.pm lib/Proc/Background/Win32.pm t/01proc.t t/author-pod-syntax.t t/sleep_exit.pl weaver.ini Proc-Background-1.21/dist.ini0000644000175000017500000000223513560375152017210 0ustar silverdirksilverdirkname = Proc-Background abstract = Run asynchronous child processes under Unix or Windows main_module = lib/Proc/Background.pm author = Blair Zajac author = Michael Conrad license = Perl_5 copyright_holder = Michael Conrad, (C) 1998-2009 by Blair Zajac [MetaResources] bugtracker.web = https://github.com/nrdvana/perl-proc-background/issues repository.web = https://github.com/nrdvana/perl-proc-background repository.url = https://github.com/nrdvana/perl-proc-background.git repository.type = git [@Git] [Git::Contributors] [Git::GatherDir] exclude_match = ^t/tmp include_untracked = 0 [Encoding] encoding = bytes match = ^t/data/ [Git::NextVersion] [PkgVersion] [MakeMaker::Awesome] header_file = Makefile.header WriteMakefile_arg = PL_FILES => { %{$WriteMakefileArgs{PL_FILES}||{}}, %optional_PL_FILES } WriteMakefile_arg = EXE_FILES => [ @{$WriteMakefileArgs{EXE_FILES}||[]}, @optional_EXE_FILES ] [OSPrereqs / MSWin32] Win32::Process = 0.04 Win32::ShellQuote = 0.003001 [PodWeaver] [ExtraTests] [PodSyntaxTests] [Manifest] [License] [MetaYAML] [MetaJSON] [UploadToCPAN] Proc-Background-1.21/LICENSE0000644000175000017500000004401513560375152016553 0ustar silverdirksilverdirkThis software is copyright (c) 2019 by Michael Conrad, (C) 1998-2009 by Blair Zajac. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2019 by Michael Conrad, (C) 1998-2009 by Blair Zajac. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2019 by Michael Conrad, (C) 1998-2009 by Blair Zajac. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Proc-Background-1.21/Changes0000644000175000017500000002636213560375152017046 0ustar silverdirksilverdirkTue Nov 5 17:39:00 EST 2019 Version 1.21 * Fix bug in timeout_system that caused it to wait the maximum duration on every call. Sun Nov 3 19:34:00 EST 2019 Version 1.20 * More correct parsing of Win32 arguments to determine executable name, and more correct quoting when building command line when starting from an argv. * More correct use of Unix signals during ->die, but also give user the ability to specify a custom sequence of signals. * Emulate Unix exit status of SIGKILL on Win32 when process was ended using $proc->Kill * New attributes ->exit_code and ->exit_signal help inspect the wstat value returned by ->wait. * Fix Win32 path separator used when searching %PATH% for exe * Don't leak changes to $? when calling ->die() during DESTROY * Make sure all die_upon_destroy happens before global destruction * Re-tooled with Dist::Zilla for modern generation of MYMETA and automatic version, license, etc. Sun Jul 5 15:40:32 PDT 2009 * Release version 1.10. Sun Jul 5 15:15:12 PDT 2009 * Makefile.PL: Resolve https://rt.cpan.org/Ticket/Display.html?id=47100 by passing PREREQ_PM to WriteMakefile(). Patch by: Tomas Doran Wed Jul 1 22:58:13 PDT 2009 * README: Correct the URL to the Subversion repository for this project. Wed Jul 1 22:46:11 PDT 2009 * Release version 1.09. Wed Jul 1 22:36:06 PDT 2009 * Makefile.PL: Switch from die() to warn() if Win32::Process isn't installed into a warning. When running under CPAN.pm, the die causes the install to fail before processing dependencies. Reducing this to a warning means that CPAN will cleanly install Proc::Background and Win32::Process with no user intervention needed in strawberry perl or even ActiveState if you have a working make. Patch by: Tomas Doran Sat Dec 7 09:41:58 PST 2002 * Release version 1.08. Sat Dec 7 09:33:53 PST 2002 Blair Zajac * lib/Proc/Background/Win32.pm (_new): When more than one argument is passed to _new in @_, each array element may be quoted to protect whitespace so that the final assembly of the individual arguments into one string, using "@_", that is passed to Win32::Process::Create works. An empty string was not being protected and was lost from the command line arguments. Bug fix by Jim Hahn . * README: Note that this package is hosted in a Subversion repository and give its URL. * Changes: Renamed from CHANGES. Sat Apr 20 19:27:53 PDT 2002 Blair Zajac * Release version 1.07. Sat Apr 20 18:55:46 PDT 2002 Blair Zajac * lib/Proc/Background/Win32.pm: Fix a bug spotted by John Kingsley on Windows platforms where if Proc::Background->new is passed an absolute pathname to a program containing whitespace, then Win32::Process::Create will not be able to create the new process. The solution is use Win32::GetShortPathName to convert the long pathname into a short pathname with no spaces. Also eval "use Win32' to load Win32::GetShortPathName. Sat Apr 20 18:35:57 PDT 2002 Blair Zajac * lib/Proc/Background.pm: Fix a bug spotted by Ruben Diez in _resolve_path where if one of the directories in the PATH had a directory with the same name as the program being searched for, the directory would be used because they typically have execute permissions. Now check for a file and the execute permissions before using the file. Sat Apr 20 18:19:27 PDT 2002 Blair Zajac * lib/Proc/Background.pm: Fix all cases where a string containing '0' would fail a test even though it should pass. * lib/Proc/Background/Unix.pm: Ditto. * lib/Proc/Background/Win32.pm: Ditto. Sat Sep 8 12:20:01 PDT 2001 Blair Zajac * Release version 1.06. Sat Sep 8 12:19:39 PDT 2001 Blair Zajac * t/01proc.t: On Cygwin test 46 fails intermittently when it tries to see if the spawned process is running by using kill(0, $pid). It's not clear why this would happen, but sometimes kill returns 0, even though the process should be running. Maybe it's the Cygwin layer that is causing the problem. Adding a one second sleep before calling kill seems to cause the test to pass. * t/sleep_exit.t: The sleep argument was being set to 1 even if the command line argument was 0 because $sleep was checked for trueness, not if it was defined. Now check $sleep and $exit_status for being defined before setting them. * README: Update the instructions for checking and installing Win32::Process for Perl on Windows. Tue Aug 28 12:54:44 PDT 2001 Blair Zajac * Release version 1.05. Tue Aug 28 12:34:15 PDT 2001 Blair Zajac * lib/Proc/Background.pm: The $VERSION variable was being set using $VERSION = substr q$Revision: 1.05 $, 10;' which did not properly set $VERSION to a numeric value in Perl 5.6.1 probably due to the trailing ' ' character after the number. This resulted in 'use Proc::Background 1.04' failing to force Perl to use version 1.04 or newer of Proc::Background even if 1.03 or older was installed because $VERSION was set using substr and Perl would not consider $VERSION to be set. Now use the longer but effective: $VERSION = sprintf '%d.%02d', '$Revision: 1.05 $' =~ /(\d+)\.(\d+)/; * lib/Proc/Background/Unix.pm: Ditto. * lib/Proc/Background/Win32.pm: Ditto. Thu Aug 16 14:36:39 PDT 2001 Blair Zajac * Release version 1.04. Thu Aug 16 14:29:14 PDT 2001 Blair Zajac * lib/Proc/Background.pm: When new is passed an incorrect number of arguments, do confess using the class passed to new, rather use the hardwired Proc::Background class which will make error messages easier to understand since module complaining about the error will be the correct one. * lib/Proc/Background/Unix.pm: Ditto, except for _new, not new. * lib/Proc/Background/Win32.pm: Ditto, except for _new, not new. Thu Aug 16 14:00:41 PDT 2001 Blair Zajac * lib/Proc/Background.pm: Proc::Background::new can accept a reference to a hash as its first argument which contains key/value pairs to modify Proc::Background's behavior. Currently the only key understood is `die_upon_destroy' which has the process killed via die() when the Proc::Background object is being DESTROY'ed. * t/01proc.t: Add tests to test the new options behavior. Thu Aug 16 13:30:23 PDT 2001 Blair Zajac * lib/Proc/Background.pm: No longer use cluck and return undef to warn about invalid arguments to function calls. Instead just call confess to print the call stack and quit the script. * lib/Proc/Background/Unix.pm: Ditto. * lib/Proc/Background/Win32.pm: Ditto. Tue Aug 14 22:50:14 PDT 2001 Blair Zajac * lib/Proc/Background/Win32.pm: Remove an unnecessary loop label in _die. * lib/Proc/Background.pm: Update the documentation to be clearer. * README: Remove the reference to my FTP site, as it is no longer being used. * README: Update all references to Blair Zajac's email addresses to blair@orcaware.com. * CHANGES: Ditto. * lib/Proc/Background/Unix.pm: Ditto. * lib/Proc/Background/Win32.pm: Ditto. * lib/Proc/Background.pm: Ditto. Sun Feb 4 13:54:37 PST 2001 Blair Zajac * Release version 1.03. Sun Feb 4 11:50:15 PST 2001 Blair Zajac * Add a new command line option to timed-process, -e, that takes an integer argument. This value sets the exit value timed-process uses for its exit call when it has to kill the given program because the timeout elapsed. This value is not used if the process exits before the timeout expires. * t/01proc.t: Add tests for for the timed-process script. Sat Feb 3 14:21:32 PST 2001 Blair Zajac * Change all occurrences of Proc::Generic, which was the original name of this module, with Proc::Background in every file in the module. This includes fixing the timed-process script which used Proc::Generic instead of Proc::Background. Mon Jan 15 16:05:04 PST 2001 Blair Zajac * Release version 1.02. Mon Jan 15 10:32:59 PST 2001 Blair Zajac * Make Proc::Background::new flexible enough to behave in the same manner as exec() or system() do when passed either a single or multiple arguments. When the command to put in the background run is passed as an array with two or more elements, run the command directly without passing the command through the shell. When a single argument is passed to Proc::Background::new, pass the command through the shell. Add a new test to the test suite to check a command passed as a single argument to Proc::Background::new. * Remove 'Unrecognized escape \w passed through at Background.pm line 30' warning when using Perl 5.6.0. Wed Jun 21 09:51:37 PDT 2000 Blair Zajac * Release version 1.01. Wed Jun 21 09:47:33 PDT 2000 Blair Zajac * Proc::Background::Win32 used to only protect arguments that contained he space character by placing "'s around the argument. Now, make sure that each individual argument to Proc::Backgrond ends up going to the Windows shell in such a way that the shell sees the argument as a single argument. This means escaping "'s that are not already escaped and placing "'s around the argument if it matches \s. This will protect the string if it finds a \s in it and not just a space. Thu Apr 20 14:46:31 PDT 2000 Blair Zajac * Release version 1.00. Thu Apr 20 14:40:11 PDT 2000 Blair Zajac * In certain circumstances on older Perls, Proc::Background would complain that @_ could not be modified since it is a read only variable. Make a copy of @_ and modify that. Wed Apr 19 19:50:51 PDT 2000 Blair Zajac * Release version 0.03. Wed Apr 19 14:47:58 PDT 2000 Blair Zajac * Relax the requirement that the path to the program has to be absolute. If it is not absolute, then look for the absolute location of the program. * Add a new method named pid that returns the process ID of the new process. Sun Jun 28 12:43:39 PDT 1998 Blair Zajac * Release version 0.02. Tue Jun 23 15:13:13 PDT 1998 Blair Zajac * Restructure the die method. Keep the OS independent code for killing a process in Proc::Background and the OS dependent killing code in Proc::Background::*. * Update the POD for Proc::Background to be more explicit about what start_time and end_time return. * Fix bugs in Proc::Background::Win32. * Update Makefile.PL to check for Win32::Process installed on Win32 systems. Thu Jun 18 14:52:01 PDT 1998 Blair Zajac * Update the README to indicate that libwin32 is only needed on Win32 systems. * Remove calls to croak or die. Call cluck instead. * Fix the implementation documentation. * Remove Proc::Background::Win32::alive since Proc::Background::alive works. Thu Apr 24 12:00:00 PDT 1998 Blair Zajac * Version 0.01 Proc-Background-1.21/README0000644000175000017500000000661013560375152016425 0ustar silverdirksilverdirkPackage Proc::Background Version 1.21 This is the Proc::Background package. It provides a generic interface to running background processes. Through this interface, users can run background processes on different operating systems without concerning themselves about the specifics of doing this. Users of this package create new Proc::Background objects that provide an object oriented interface to process management. The following methods are provided to users of the Proc::Background package: new: start a new background process. alive: test to see if the process is still alive. die: reliably try to kill the process. wait: wait for the process to exit and return the exit status. start_time: return the time that the process started. end_time: return the time when the exit status was retrieved. A generic function, timed-system, is also included that lets a background process run for a specified amount of time, and if the process did not exit, then the process is killed. AVAILABILITY The latest released version of this package is available for download from a CPAN (Comprehensive Perl Archive Network) archive near you in https://metacpan.org/pod/proc::Background The package's source code is hosted in a Git repository at https://github.com/nrdvana/perl-Proc-Background INSTALLATION In order to use this package you will need Perl version 5.004_04 or better. On Win32 systems Proc::Background requires the Win32::Process and Win32::ShellQuote modules. To check if your Perl has Win32::Process installed on it, run perl Makefile.PL If this command does not complain about missing Win32::Process, then you have the module installed. If you receive an error message, you can do two things to resolve this. If you have not performed extensive customization and installation of modules into your Perl, the easier path is to upgrade to the latest version of ActiveState Perl at http://aspn.activestate.com/ASPN/Downloads/ActivePerl/ which includes Win32::Process. If you want to use your current Perl installation, then download the latest version of the libwin32 package by Gurusamy Sarathy available at: http://www.perl.com/CPAN/authors/id/GSAR/ Once that is completed, you install Proc::Background as you would install any perl module library, by running these commands: perl Makefile.PL make make test make install You can edit the configuration section of Makefile.PL to select which programs to install in addition to the library itself. If you don't want to install any programs (only the library files) and don't want to mess with the Makefile.PL then pass the '-n' option to Makefile.PL: perl Makefile.PL -n If you want to install a private copy of this package in some other directory, then you should try to produce the initial Makefile with something like this command: perl Makefile.PL LIB=~/perl DOCUMENTATION See the CHANGES file for a list of recent changes. POD style documentation is included in all modules and scripts. These are normally converted to manual pages end installed as part of the "make install" process. You should also be able to use the 'perldoc' utility to extract documentation from the module files directly. COPYRIGHT Copyright (C) 1998-2005 Blair Zajac. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.