Zing::Fork - Fork Manager
Scheme Fork Manager
use Zing::Fork; use Zing::Process; my $scheme = ['MyApp', [], 1]; my $fork = Zing::Fork->new(scheme => $scheme, parent => Zing::Process->new); # $fork->execute;
This package provides provides a mechanism for forking and tracking processes, as well as establishing the parent-child relationship. Note: The $num part of the application scheme, i.e. ['MyApp', [], $num], is ignored and launching the desired forks requires calling "execute" multiple times.
$num
['MyApp', [], $num]
This package uses type constraints from:
Zing::Types
This package has the following attributes:
parent(Process)
This attribute is read-only, accepts (Process) values, and is required.
(Process)
processes(HashRef[Process])
This attribute is read-only, accepts (HashRef[Process]) values, and is optional.
(HashRef[Process])
scheme(Scheme)
This attribute is read-only, accepts (Scheme) values, and is required.
(Scheme)
space(Space)
This attribute is read-only, accepts (Space) values, and is optional.
(Space)
This package implements the following methods:
execute() : Process
The execute method forks a process based on the scheme, adds it to the process list and returns a representation of the child process.
# given: synopsis my $process = $fork->execute;
monitor() : HashRef[Int]
The monitor method calls "waitpid" in perlfunc on tracked processes and returns the results as a pid/result map.
# given: synopsis $fork->execute; $fork->execute; # forks still alive my $results = $fork->monitor; # { 1000 => 1000, ... }
# given: synopsis $fork->execute; $fork->execute; # forks are dead my $results = $fork->monitor; # { 1000 => -1, ... }
sanitize() : Int
The sanitize method removes inactive child processes from the process list and returns the number of processes remaining.
# given: synopsis $fork->execute; # dead $fork->execute; # dead my $results = $fork->sanitize; # 0
# given: synopsis $fork->execute; # live $fork->execute; # dead my $results = $fork->sanitize; # 1
# given: synopsis $fork->execute; # live $fork->execute; # live my $results = $fork->sanitize; # 2
terminate(Str $signal = 'kill') : HashRef[Int]
The terminate method call "kill" in perlfunc and sends a signal to all tracked processes and returns the results as a pid/result map.
# given: synopsis $fork->execute; $fork->execute; my $results = $fork->terminate; # kill
# given: synopsis $fork->execute; $fork->execute; my $results = $fork->terminate('term');
# given: synopsis $fork->execute; $fork->execute; my $results = $fork->terminate('usr2');
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To install Zing, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Zing
CPAN shell
perl -MCPAN -e shell install Zing
For more information on module installation, please visit the detailed CPAN module installation guide.