For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2005 > finding the PID of a process running as an anonymous pipe









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author finding the PID of a process running as an anonymous pipe
Richard

2005-05-27, 4:00 pm

I need to find the PID of a process running as an anonymous pipe, that is I
have this code

$fh = new FileHandle;
open($fh, "tail -f $filename |") or die ..........

I want to get the PID of the tail -f process when runing under linux, I
could do it by looking at the output of ps -fwu $userid | grep "tail -f
$filename", but that seems like over kill :-)

Thanks.
Richard.


Anno Siegel

2005-05-27, 4:00 pm

Richard <user@host.com> wrote in comp.lang.perl.misc:
> I need to find the PID of a process running as an anonymous pipe, that is I
> have this code
>
> $fh = new FileHandle;
> open($fh, "tail -f $filename |") or die ..........
>
> I want to get the PID of the tail -f process when runing under linux, I
> could do it by looking at the output of ps -fwu $userid | grep "tail -f
> $filename", but that seems like over kill :-)


"perldoc -f open" will answer that. Also see "perldoc -q tail".

Anno
Richard

2005-05-27, 4:00 pm

DOH! Thanks :-)

Please accept my humble apologies for not RTFM :-)

Anno Siegel wrote:
> Richard <user@host.com> wrote in comp.lang.perl.misc:
>
>
>
> "perldoc -f open" will answer that. Also see "perldoc -q tail".
>
> Anno

Brian McCauley

2005-05-27, 4:00 pm

Richard wrote:

> I need to find the PID of a process running as an anonymous pipe,


I know you've no RTDMed at Anno's suggestion so I won't adderess that.

> $fh = new FileHandle;


In recent Perl the above is redundant - open() autovivifies.

> open($fh, "tail -f $filename |") or die ..........


In recent perl rather than combining the mode and all the exec()
arguments into a string and having perl (or even /bin/sh) pull them
appart again, you can acually give them as a list. This is far cleaner.

open($fh, '-|', 'tail', '-f', $filename) or die ..........
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com