NAME
Zing::Fork - Fork Manager
ABSTRACT
Scheme Fork Manager
SYNOPSIS
use Zing::Fork;
use Zing::Process;
my $scheme = ['MyApp', [], 1];
my $fork = Zing::Fork->new(scheme => $scheme, parent => Zing::Process->new);
# $fork->execute;
DESCRIPTION
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.
LIBRARIES
This package uses type constraints from:
ATTRIBUTES
This package has the following attributes:
parent
parent(Process)
This attribute is read-only, accepts (Process)
values, and is required.
processes
processes(HashRef[Process])
This attribute is read-only, accepts (HashRef[Process])
values, and is optional.
scheme
scheme(Scheme)
This attribute is read-only, accepts (Scheme)
values, and is required.
space
space(Space)
This attribute is read-only, accepts (Space)
values, and is optional.
METHODS
This package implements the following methods:
execute
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.
monitor
monitor() : HashRef[Int]
The monitor method calls "waitpid" in perlfunc on tracked processes and returns the results as a pid/result map.
- monitor example #1
-
# given: synopsis $fork->execute; $fork->execute; # forks still alive my $results = $fork->monitor; # { 1000 => 1000, ... }
- monitor example #2
-
# given: synopsis $fork->execute; $fork->execute; # forks are dead my $results = $fork->monitor; # { 1000 => -1, ... }
sanitize
sanitize() : Int
The sanitize method removes inactive child processes from the process list and returns the number of processes remaining.
- sanitize example #1
-
# given: synopsis $fork->execute; # dead $fork->execute; # dead my $results = $fork->sanitize; # 0
- sanitize example #2
-
# given: synopsis $fork->execute; # live $fork->execute; # dead my $results = $fork->sanitize; # 1
- sanitize example #3
-
# given: synopsis $fork->execute; # live $fork->execute; # live my $results = $fork->sanitize; # 2
terminate
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.
- terminate example #1
-
# given: synopsis $fork->execute; $fork->execute; my $results = $fork->terminate; # kill
- terminate example #2
-
# given: synopsis $fork->execute; $fork->execute; my $results = $fork->terminate('term');
- terminate example #3
-
# given: synopsis $fork->execute; $fork->execute; my $results = $fork->terminate('usr2');
AUTHOR
Al Newkirk, awncorp@cpan.org
LICENSE
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".