分叉时草莓 Perl 负子 pid
Strawberry Perl negative child pid when forked
所以我了解到 Windows 不支持 Unix fork-exec 模型,而是生成进程。但是,Strawberry Perl 的 fork 仿真会生成具有负 PID 的子代。这些 PID 似乎是一致的,但我不明白为什么它们是负数,或者,实际上,Perl 是如何模拟 Unix 分支的。
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";
}
这会产生类似于:
I'm the parent, pid is 3428, cpid is -2600
I'm the child, pid is -2600
大部分细节都在 perlfork 中,但为了回答您的具体问题,Windows 上的 Perl 伪进程实际上是作为线程实现的。您应该将正 PID 解释为原始线程的实际 PID,而负 PID 实际上是线程 ID(当然取反)。
如果 fork
创建的假进程(实际上是线程)使用正 PID,它们可能会与实际进程的 PID 冲突。
所以我了解到 Windows 不支持 Unix fork-exec 模型,而是生成进程。但是,Strawberry Perl 的 fork 仿真会生成具有负 PID 的子代。这些 PID 似乎是一致的,但我不明白为什么它们是负数,或者,实际上,Perl 是如何模拟 Unix 分支的。
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";
}
这会产生类似于:
I'm the parent, pid is 3428, cpid is -2600
I'm the child, pid is -2600
大部分细节都在 perlfork 中,但为了回答您的具体问题,Windows 上的 Perl 伪进程实际上是作为线程实现的。您应该将正 PID 解释为原始线程的实际 PID,而负 PID 实际上是线程 ID(当然取反)。
如果 fork
创建的假进程(实际上是线程)使用正 PID,它们可能会与实际进程的 PID 冲突。