in reply to wrong pid

With that code
$cmd="$scriptsdir/process_tar.pl $file >> /tmp/testlog &"; + + $pid=open(PID,"|$cmd");

you are opening a pipe to a shell which then runs perl. The shell and the perl process don't have the same PID:

#!/usr/bin/perl # file pid.pl sleep 1; print "$0 PID: $$\n";
#!/usr/bin/perl my $cmd = 'echo my PID is $$ && ./pid.pl'; my $pid = open PID, "| $cmd" or die "Can't run ./pid.pl: $!\n"; print "PID returned by open: $pid\n"; sleep 2; __END__ my PID is 4465 PID returned by open: 4465 ./pid.pl PID : 4466

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: wrong pid
by js1 (Monk) on Apr 23, 2007 at 13:55 UTC
    Thanks. That makes sense. What's the correct way to do this then? How do I get the perl program's pid instead of the shell?