[EMAIL PROTECTED] wrote:

The reason your code prints pid twice, is in the placement of your print statment. Since you placed your print code after your fork statment, both parent and child read that statment. Inside that block Parent will see pid of ' 0 ' for child, which is normaly a condition used to split the two apart. You can use <C> getpid, to get the read PID of process. Your code should look something like this:

#!/bin/perl
use strict;
use warnings;
$|=1;

defined( my $pid = fork ) or die "Cannot fork: $!";

if( $pid ) {
print "I am the parent with pid: ",getpid(),"\n";

Perl doesn't have a getpid() function.

$ perl -le' print getpid() '
Undefined subroutine &main::getpid called at -e line 1.


The PID is available in the $$ variable:

$ perl -le' print $$ '
6389


If you want the getpid() function you have to use the POSIX module:

$ perl -MPOSIX -le' print getpid() '
6390



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to