Use PAR::Packer - pp when use fork
Vld SFR <[email protected]> Sat, 25 Apr 2020 18:50:34 +0200
| Newsgroups | gmane.comp.lang.perl.par |
|---|---|
| Message-ID | <[email protected]> |
Hello, first thank you for creating PAR: Packer Unfortunately when I use
fork or modules using fork like POE :: Wheel :: run or Parallel ::
ForkManager the script ends before the fork son hands over. If below an
example Version perl : perl 5, version 28, subversion 2 (v5.28.2) built
for MSWin32-x86-multi-thread-64int Windows 10 64Bits Script test :
> use strict;
> use warnings;
> use diagnostics;
> use 5.010;
>
> my $name = 'Foo';
>
> say "PID $$";
> my $pid = fork();
> die if not defined $pid;
> if (not $pid) {
> say "In child ($name) - PID $$ ($pid)";
> $name = 'Qux';
> sleep 2;
> say "In child ($name) - PID $$ ($pid)";
> exit;
> }
>
> say "In parent ($name) - PID $$ ($pid)";
> $name = 'Bar';
> sleep 2;
> say "In parent ($name) - PID $$ ($pid)";
>
> my $finished = wait();
> say "In parent ($name) - PID $$ finished $finished";
display
PID 9400
In parent (Foo) - PID 9400 (-9928)
In child (Foo) - PID -9928 (0)
In parent (Bar) - PID 9400 (-9928)
In child (Qux) - PID -9928 (0)
In parent (Bar) - PID 9400 finished -9928
pack : pp -c -x fork.pl -o fork.exe
Display:
> PID 8384
> In parent (Foo) - PID 8384 (-4572)
> In child (Foo) - PID -4572 (0)
> In parent (Bar) - PID 8384 (-4572)
> In child (Qux) - PID -4572 (0)
The finished script without waiting for the children how to use pp with
scripts using fork