`perlfork` notes that DESTROY methods and END blocks will still be
called in a "child" pseudo-process which calls "exec".
But this is a major flaw in the fork emulation, likely to break distant
unsuspecting code.
For example the following runs "Cleanup" twice on Windows (Strawberry
Perl 5.32):
use strict; use warnings;
use Guard qw(guard scope_guard);
{
scope_guard { warn "CLEANUP!\n"; };
my $pid = fork;
if ($pid == 0) { exec("date /T"); die "Exec failed"; }
waitpid($pid,0);
}
Or as a 1-liner:
perl -MGuard -e "{scope_guard{warn qq(CLEANUP\n)}; if (($pid=fork)==0) {
exec q(date /T); die $!;} waitpid($pid,0); }"
I'm wondering if "exec" can terminate the extra interpreter *without*
running any cleanup, or rather some kind of wholesale memory
reclamation of the whole interpreter without running DESTROY or END blocks.
Or is there another way to make fork emulation more transparent?
-Jim
called in a "child" pseudo-process which calls "exec".
But this is a major flaw in the fork emulation, likely to break distant
unsuspecting code.
For example the following runs "Cleanup" twice on Windows (Strawberry
Perl 5.32):
use strict; use warnings;
use Guard qw(guard scope_guard);
{
scope_guard { warn "CLEANUP!\n"; };
my $pid = fork;
if ($pid == 0) { exec("date /T"); die "Exec failed"; }
waitpid($pid,0);
}
Or as a 1-liner:
perl -MGuard -e "{scope_guard{warn qq(CLEANUP\n)}; if (($pid=fork)==0) {
exec q(date /T); die $!;} waitpid($pid,0); }"
I'm wondering if "exec" can terminate the extra interpreter *without*
running any cleanup, or rather some kind of wholesale memory
reclamation of the whole interpreter without running DESTROY or END blocks.
Or is there another way to make fork emulation more transparent?
-Jim