Determine a child PID

J

Joey

I am trying to determine the PID when opening of a file handle from within
my main perl code. Here is a snip where i call the open file handle.

$infile = 'infile';
open(IF, "tail -f $infile|") or die "Cannot open pipe $infile\n";

while (<IF>) {
do_smothing()
}

In the example below in unix the main perl code has a pid of perl variable
$$ (PID=18629) then the open file handle has another PID, a child of the
parent (PID = 18630)

% ps -ef| grep tail
user 18632 18455 0 10:42:06 pts/10 0:00 grep tail
user 18630 18629 0 10:42:02 pts/10 0:00 tail -f infile
% ps -ef| grep myscript.pl
user 18634 18455 0 10:42:12 pts/10 0:00 grep myscript.pl
user 18629 18455 0 10:42:02 pts/10 0:00 /usr/bin/perl ./myscript.pl

Is there a way within perl to get the child PID 18630 ?

Thanks in advance.
Joey
 
J

John Strauss

On 15 Jul 2003 07:47:14 -0700
I am trying to determine the PID when opening of a file handle from within
my main perl code. Here is a snip where i call the open file handle.

$infile = 'infile';
open(IF, "tail -f $infile|") or die "Cannot open pipe $infile\n";

while (<IF>) {
do_smothing()
}

In the example below in unix the main perl code has a pid of perl variable
$$ (PID=18629) then the open file handle has another PID, a child of the
parent (PID = 18630)

% ps -ef| grep tail
user 18632 18455 0 10:42:06 pts/10 0:00 grep tail
user 18630 18629 0 10:42:02 pts/10 0:00 tail -f infile
% ps -ef| grep myscript.pl
user 18634 18455 0 10:42:12 pts/10 0:00 grep myscript.pl
user 18629 18455 0 10:42:02 pts/10 0:00 /usr/bin/perl ./myscript.pl

Is there a way within perl to get the child PID 18630 ?

Thanks in advance.
Joey

open() should do that for you. it's in "perldoc -f open",
the bit where it says: "If the `open' involved a pipe, the
return value happens to be the pid of the subprocess."

which is nice.




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
 
J

Jeff 'japhy' Pinyan

[posted & mailed]

I am trying to determine the PID when opening of a file handle from within
my main perl code. Here is a snip where i call the open file handle.

$infile = 'infile';
open(IF, "tail -f $infile|") or die "Cannot open pipe $infile\n";

When open() is doing more than just opening a file (that is, when you're
piping), it returns not only success or failure, but the actual PID.

my $pid = open(TAIL, "tail -f $infile |")
or die "cannot `tail -f $infile`: $!";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top