Doit::Fork - run code in another process
use Doit; use Doit::Log; sub run_test { my(undef, $arg) = @_; return "running in process $$ with arg $arg"; } return 1 if caller; my $doit = Doit->init; $doit->add_component('fork'); my $fork = $doit->do_fork; info $fork->call_with_runner('run_test', 'test argument');
This component provides a function do_fork, which forks a new process and returns a new Doit runner (like "do_ssh_connect" in Doit or "do_sudo" in Doit. This process is capable of running subroutines (using call_with_runner or call), or any other core Doit function.
do_fork
call_with_runner
call
A possible use case is to have multiple separated processes, but with the ability (unlike with normal forked processes) to call subroutines in these processes with possibly complex arguments and return values.
Note that all communication is still synchronous.
Slaven Rezic <srezic@cpan.org>
Copyright (c) 2017,2023 Slaven Rezic. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Doit, "fork" in perlfunc
To install Doit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Doit
CPAN shell
perl -MCPAN -e shell install Doit
For more information on module installation, please visit the detailed CPAN module installation guide.