Write to pipe from another process? - Unix

This is a discussion on Write to pipe from another process? - Unix ; I have a process that starts a bunch of other processes. When this super process starts, it creates a pipe and dup's the write ends to stdout/stderr so all the child processes inherit that pipe as their stdout/stderr. The super ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Write to pipe from another process?

  1. Write to pipe from another process?

    I have a process that starts a bunch of other processes. When this
    super process starts, it creates a pipe and dup's the write ends to
    stdout/stderr so all the child processes inherit that pipe as their
    stdout/stderr. The super process then reads from that pipe to collect
    the output from all the child processes to log it to a centralized
    log.

    That all works, but now I have a process that's started from the shell
    so it doesn't inherit the super process'es pipe as its stdout/stderr.
    What I'd like to do is if this process goes into a certain mode, I
    want to send output to that other super process'es pipe so it can go
    to the centralized log. But I'm not sure how I can get a file
    descriptor to that global pipe.

    Is there a way for a process to publish its pipe so another process
    can open it? I know I can use a Unix domain socket and bind to a path,
    but as far as I know, I'd need to listen for connection requests in
    the server and each accept would give a completely separate pipe. I
    want all processes to use the same underlying pipe (like they do when
    the super process does fork/exec). It's a closed system and all
    processes are running as root so I'm not worried about permissions.

  2. Re: Write to pipe from another process?

    >I have a process that starts a bunch of other processes. When this
    >super process starts, it creates a pipe and dup's the write ends to
    >stdout/stderr so all the child processes inherit that pipe as their
    >stdout/stderr. The super process then reads from that pipe to collect
    >the output from all the child processes to log it to a centralized
    >log.


    You could start another child process which creates a named
    pipe, then reads from it and writes down the inherited pipe.

    >That all works, but now I have a process that's started from the shell
    >so it doesn't inherit the super process'es pipe as its stdout/stderr.
    >What I'd like to do is if this process goes into a certain mode, I
    >want to send output to that other super process'es pipe so it can go
    >to the centralized log. But I'm not sure how I can get a file
    >descriptor to that global pipe.


    Then the independent process can open the named pipe (see above)
    and write something down it. It's not the global pipe, but what
    you write gets copied there.

    >Is there a way for a process to publish its pipe so another process
    >can open it?


    Named pipes.

    >I know I can use a Unix domain socket and bind to a path,
    >but as far as I know, I'd need to listen for connection requests in
    >the server and each accept would give a completely separate pipe. I
    >want all processes to use the same underlying pipe (like they do when
    >the super process does fork/exec). It's a closed system and all
    >processes are running as root so I'm not worried about permissions.


    Is there a reason why the approach above won't work?


  3. Re: Write to pipe from another process?

    > Named pipes.

    Thanks, that's exactly what I need.


  4. Re: Write to pipe from another process?

    "skillzero@gmail.com" writes:

    [...]

    > Is there a way for a process to publish its pipe so another process
    > can open it? I know I can use a Unix domain socket and bind to a path,
    > but as far as I know, I'd need to listen for connection requests in
    > the server and each accept would give a completely separate pipe.


    Only for stream sockets. A single datagram socket could receive
    messages from multiple feeders. But using a FIFO (named pipe) is
    usually easier because it can just be opened like a file.

+ Reply to Thread