Gre*_*bet 1 windows perl fork strawberry-perl
因此,我了解Windows不支持Unix fork-exec模型,而是生成进程。但是,Strawberry Perl的fork仿真会产生带有负PID的子代。这些PID似乎是一致的,但是我不明白为什么它们是负数,或者说实际上是Perl如何模拟Unix fork。
use strict;
use warnings;
my $cpid = fork();
if ($cpid == 0) {
printf "%s\n", "I'm the child, pid is $$";
} else {
printf "%s\n", "I'm the parent, pid is $$, cpid is $cpid";
}
Run Code Online (Sandbox Code Playgroud)
这将产生类似于以下内容的信息:
I'm the parent, pid is 3428, cpid is -2600
I'm the child, pid is -2600
Run Code Online (Sandbox Code Playgroud)