Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Determine a child PID

Reply
Thread Tools

Determine a child PID

 
 
Joey
Guest
Posts: n/a
 
      07-15-2003
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
 
Reply With Quote
 
 
 
 
John Strauss
Guest
Posts: n/a
 
      07-15-2003
On 15 Jul 2003 07:47:14 -0700
(Joey) wrote:
>
> 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
 
Reply With Quote
 
 
 
 
Jeff 'japhy' Pinyan
Guest
Posts: n/a
 
      07-15-2003
[posted & mailed]

On 15 Jul 2003, Joey wrote:

>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`: $!";

--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Best way to determine if a certain PID is still running Lars =?iso-8859-15?Q?Gust=E4bel?= Python 2 02-04-2006 01:04 AM
Best way to determine if a certain PID is still running David Hirschfield Python 3 02-03-2006 03:32 PM
How to determine the PID of your Java program andreww100@gmail.com Java 3 07-24-2005 10:25 PM
child pid Aless C Programming 3 04-25-2004 11:37 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57