派克草莓Perl阴性儿童pid

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)

tjd*_*tjd 5

大多数细节都在perlfork中,但是为了回答您的特定问题,Windows上Perl的伪进程实际上是作为线程实现的。您应该将正PID解释为原始线程的实际PID,而负PID则实际上是线程ID(当然是负的)。