C
ccc31807
On Win32, the process id is whatever the value of $$ is.
When you fork(), the parent retains whatever the original pid was.
However, the child pid has a negative number. Why?
CODE
my $orig_pid = $$;
my $child = fork();
if ($$ > 0)
{
print qq(1. The pid is $$\n);
print qq(Parent process pid is $$, child is $child\n);
}
else
{
print qq(2. The pid is $$\n);
print qq(Child process pid is $$, parent is $orig_pid\n);
}
OUTPUT
1. The pid is 3172
Parent process pid is 3172, child is -2272
2. The pid is -2272
Child process pid is -2272, parent is 3172
When you fork(), the parent retains whatever the original pid was.
However, the child pid has a negative number. Why?
CODE
my $orig_pid = $$;
my $child = fork();
if ($$ > 0)
{
print qq(1. The pid is $$\n);
print qq(Parent process pid is $$, child is $child\n);
}
else
{
print qq(2. The pid is $$\n);
print qq(Child process pid is $$, parent is $orig_pid\n);
}
OUTPUT
1. The pid is 3172
Parent process pid is 3172, child is -2272
2. The pid is -2272
Child process pid is -2272, parent is 3172