finding the PID of a process running as an anonymous pipe

Discussion in 'Perl Misc' started by Richard, May 27, 2005.

  1. Richard

    Richard Guest

    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.
     
    Richard, May 27, 2005
    #1
    1. Advertising

  2. Richard

    Anno Siegel Guest

    Richard <> 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
     
    Anno Siegel, May 27, 2005
    #2
    1. Advertising

  3. 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 ..........
     
    Brian McCauley, May 27, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guy
    Replies:
    0
    Views:
    390
  2. P.S.
    Replies:
    0
    Views:
    329
  3. Miki Tebeka
    Replies:
    2
    Views:
    619
    Chris Angelico
    Apr 8, 2011
  4. Pito Salas
    Replies:
    11
    Views:
    247
    Robert Klemme
    Aug 26, 2009
  5. Mirco Wahab
    Replies:
    1
    Views:
    212
Loading...

Share This Page