open3 "sh -c" problem with pipes or redirect

Discussion in 'Perl Misc' started by VANOSPAM, Sep 24, 2009.

  1. VANOSPAM

    VANOSPAM Guest

    I have a perl programming that has been running for the last 10 or so
    years. It manages other processes, capturing all outputs into a
    common logfile and killing dormant processes (no output) after a given
    amount of time. The user can print processes up or down as needed.
    It utilizes the Event.pm module and it works fine. Now I I have the
    need to either run a process that utilizes a pipe "x | y" or setup two
    separate processes and redirect stdin/stdout to use a named pipe ("x
    >name_pipe" and "y <name_pipe"). In either case, the open3 call uses

    a "sh -c" to execute the command. The pid that is returned is the pid
    of the shell command and when I attempt to terminate the process only
    the shell command is killed, not the children.

    I suspect the answer is to modify the stdin/stdout file handles as
    needed and pass those to open3. Is this the correct solution or is
    there another way?

    Currently, this is running on Solaris 8 & 10, sparc and Intel. There
    is no need for portability to windows.

    Thanx.

    Brad
     
    VANOSPAM, Sep 24, 2009
    #1
    1. Advertising

  2. VANOSPAM

    C.DeRykus Guest

    On Sep 24, 9:30 am, VANOSPAM <> wrote:
    > I have a perl programming that has been running for the last 10 or so
    > years.  It manages other processes, capturing all outputs into a
    > common logfile and killing dormant processes (no output) after a given
    > amount of time.  The user can print processes up or down as needed.
    > It utilizes the Event.pm module and it works fine.  Now I I have the
    > need to either run a process that utilizes a pipe "x | y" or setup two
    > separate processes and redirect stdin/stdout to use a named pipe ("x>name_pipe" and "y <name_pipe").  In either case, the open3 call uses
    >
    > a "sh -c" to execute the command.  The pid that is returned is the pid
    > of the shell command and when I attempt to terminate the process only
    > the shell command is killed, not the children.
    >
    > I suspect the answer is to modify the stdin/stdout file handles as
    > needed and pass those to open3.  Is this the correct solution or is
    > there another way?
    >
    > Currently, this is running on Solaris 8 & 10, sparc and Intel.  There
    > is no need for portability to windows.
    >


    Since portability wouldn't be an issue, you could try a negative
    signal to target an entire process group. See perldoc -f kill or
    perldoc perlipc for details.

    --
    Charles DeRykus
     
    C.DeRykus, Sep 24, 2009
    #2
    1. Advertising

  3. VANOSPAM

    VANOSPAM Guest

    On Sep 24, 2:37 pm, "C.DeRykus" <> wrote:
    > On Sep 24, 9:30 am, VANOSPAM <> wrote:
    >
    >
    >
    > > I have a perl programming that has been running for the last 10 or so
    > > years.  It manages other processes, capturing all outputs into a
    > > common logfile and killing dormant processes (no output) after a given
    > > amount of time.  The user can print processes up or down as needed.
    > > It utilizes the Event.pm module and it works fine.  Now I I have the
    > > need to either run a process that utilizes a pipe "x | y" or setup two
    > > separate processes and redirect stdin/stdout to use a named pipe ("x>name_pipe" and "y <name_pipe").  In either case, the open3 call uses

    >
    > > a "sh -c" to execute the command.  The pid that is returned is the pid
    > > of the shell command and when I attempt to terminate the process only
    > > the shell command is killed, not the children.

    >
    > > I suspect the answer is to modify the stdin/stdout file handles as
    > > needed and pass those to open3.  Is this the correct solution or is
    > > there another way?

    >
    > > Currently, this is running on Solaris 8 & 10, sparc and Intel.  There
    > > is no need for portability to windows.

    >
    > Since portability wouldn't be an issue, you could try a negative
    > signal to target an entire process group. See perldoc -f kill or
    > perldoc perlipc for details.
    >
    > --
    > Charles DeRykus


    Charles,
    thank you for the input. Unfortunately I did try that and it
    failed. I also tried to setup a process group using setpgrp() but I
    did not get that to work correctly either. I may have being doing
    something wrong so that is also a possibility.

    Brad
     
    VANOSPAM, Sep 24, 2009
    #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. Dave Newberry
    Replies:
    0
    Views:
    652
    Dave Newberry
    Oct 17, 2004
  2. Sal
    Replies:
    1
    Views:
    568
  3. Yuri Leikind

    using open3.rb from a thread

    Yuri Leikind, Jan 23, 2004, in forum: Ruby
    Replies:
    1
    Views:
    100
    Joel VanderWerf
    Jan 23, 2004
  4. J. Romano
    Replies:
    0
    Views:
    163
    J. Romano
    Feb 10, 2004
  5. Replies:
    1
    Views:
    127
    Xho Jingleheimerschmidt
    Jan 23, 2009
Loading...

Share This Page