NAME

Parallel::ForkControl - Finer grained control of processes on a Unix System

SYNOPSIS

  use Parallel::ForkControl;
  my $forker = new Parallel::ForkControl(
				WatchCount		=> 1,
				MaxKids			=> 50,
				MinKids			=> 5,
				WatchLoad		=> 1,
				MaxLoad			=> 8.00
				Name			=> 'My Forker',
				Code			=> \&mysub
	);
  my @hosts = qw/host1 host2 host3 host5 host5/;
  foreach my $host (@hosts) {
	$forker->run($host);
  }

  $forker->cleanup();  # wait for all children to finish;
  .....

DESCRIPTION

Parallel::ForkControl introduces a new and simple way to deal with fork()ing. The 'Code' parameter will be run everytime the run() method is called on the fork object. Any parameters passed to the run() method will be passed to the subroutine ref defined as the 'Code' arg. This allows a developer to spend less time worrying about the underlying fork() system, and just write code.

INTERFACE

new([ Option => Value ... ])

Constructor. Creates a Parallel::ForkControl object for using. Ideally, all options should be set here and not changed, though the accessors and mutators allow such behavior, even while the run() method is being executed.

options

Name ProcessTimeOut MaxKids MinKids MaxLoad *MaxMem (unimplemented) *MaxCPU (unimplemented) Method WatchCount WatchLoad *WatchMem (unimplemented) *WatchCPU (unimplemented) Code Check_At Debug

run([ @ARGS ])

This method calls the subroutine passed as the Code option. This method handles process throttling, creation, monitoring, and reaping. The subroutine in the Code option run in the child process and all control is returned to the parent object as soon as the child is successfully created. run() will block until it is allowed to create a process or process creation fails completely. run() returns the number of kids on success, or undef on failure. NOTE: This is not the return code of your subroutine. I will eventually provide mapping to argument sets passed to run() with success/failure options and (idea) a "Report" option to enable some form of reporting based on that API.

cleanup()

This method blocks until all children have finished processing.

EXPORT

None by default.

SEE ALSO

perldoc -f fork, search CPAN for Parallel::ForkManager

AUTHOR

Brad Lhotsky <brad@divisionbyzero.net>

CONTRIBUTIONS BY

Mark Thomas <mark@ackers.net>

COPYRIGHT AND LICENSE

Copyright 2003 by Brad Lhotsky

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.