Perl and Process ID

Kurt Wall kwall
Wed May 18 21:39:44 PDT 2005


On Tuesday 17 May 2005 23:32, Matthew Carpenter enlightened us thusly:
> Kurt Wall wrote:
> > On Thursday 12 May 2005 11:45, Matthew Carpenter enlightened us
> >
> > thusly:
> >> Hi All,
> >>
> >> How do I get the currently running perl app's process ID (short
> >> of ps ax |grep )?
> >
> > $$
> >
> > as in:
> >
> > $ perl -e 'print "my pid is $$\n"'; my pid is 8079
>
> Thanks Kurt, but this gives me the same as &getppid(), which is the
> parent process.  Am I missing something?

You must be. Here's my Perl script:

#!/usr/bin/perl
$pid = $$;
$ppid = getppid();
print "pid = $pid\n";
print "ppid = $ppid\n";

Here's the output. The first command prints the shell's PID:

$ echo "$$"
3853
$ ./x.pl
pid = 3892
ppid = 3853

This is exactly what I'm expecting.

Kurt


More information about the Linux-users mailing list