Named pipe questions - Unix

This is a discussion on Named pipe questions - Unix ; Hi - Got a few questions about named pipes (NPs): (1) Can a NP be opened for reading by more than 1 process, or for writing by more than 1 process? e.g: 2 processes open for writing and 3 for ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Named pipe questions

  1. Named pipe questions

    Hi -

    Got a few questions about named pipes (NPs):

    (1) Can a NP be opened for reading by more than 1 process, or for
    writing by more than 1 process? e.g: 2 processes open for writing and 3
    for reading. Is this possible.

    (2) Are messages written to NPs buffered in the kernel? i.e. will a
    sender block immiedately after writing to the NP -- untill a process
    that has opened the pipe for reading does so?

    Thanks,

    - Olumide


  2. Re: Named pipe questions

    On Sun, 23 Oct 2005 09:46:40 -0700, 50295 wrote:

    > (1) Can a NP be opened for reading by more than 1 process, or for
    > writing by more than 1 process? e.g: 2 processes open for writing and 3
    > for reading. Is this possible.


    Yes, a named pipe can have multiple writers and multiple readers. Multiple
    writers is occassionally useful. Multiple readers are not since there is no
    practical method for ensuring a particular reader gets a specific datum.

    > (2) Are messages written to NPs buffered in the kernel? i.e. will a
    > sender block immiedately after writing to the NP -- untill a process
    > that has opened the pipe for reading does so?


    Yes, the data is buffered. But the size of the buffer varies among
    implementations. Trying to write more data than can be buffered will block
    the writer (assuming, of course, you haven't set non-blocking mode).


  3. Re: Named pipe questions

    On Sun, 23 Oct 2005 22:55:09 +0200, Pascal Bourguignon wrote:

    > "Kurtis D. Rader" writes:
    >>
    >> Yes, a named pipe can have multiple writers and multiple readers.
    >> Multiple writers is occassionally useful. Multiple readers are not since
    >> there is no practical method for ensuring a particular reader gets a
    >> specific datum.

    >
    > It's practical in the case of one-byte token messages. It's a trick used
    > by gnu make to manage its subprocesses.


    "Trick" being the important part of that sentence :-)

    Certainly there are very specialized situations where you might be able to
    successfully communicate with multiple readers of a single fifo. But they
    require that the readers read one, and only one, byte from the fifo. Not
    just one byte per read() but one byte period. Far too big a risk from a
    software maintenance perspective for my liking. There are other IPC
    mechanisms that are more robust and not much more difficult to implement.
    Anyone on my programming team who presented a solution that involved
    multiple readers of a fifo would be encouraged to consider another line of
    work :-)


  4. Re: Named pipe questions

    "Kurtis D. Rader" writes:

    > On Sun, 23 Oct 2005 22:55:09 +0200, Pascal Bourguignon wrote:
    >
    >> "Kurtis D. Rader" writes:
    >>>
    >>> Yes, a named pipe can have multiple writers and multiple readers.
    >>> Multiple writers is occassionally useful. Multiple readers are not since
    >>> there is no practical method for ensuring a particular reader gets a
    >>> specific datum.

    >>
    >> It's practical in the case of one-byte token messages. It's a trick used
    >> by gnu make to manage its subprocesses.

    >
    > "Trick" being the important part of that sentence :-)
    >
    > Certainly there are very specialized situations where you might be able to
    > successfully communicate with multiple readers of a single fifo. But they
    > require that the readers read one, and only one, byte from the fifo. Not
    > just one byte per read() but one byte period. Far too big a risk from a
    > software maintenance perspective for my liking. There are other IPC
    > mechanisms that are more robust and not much more difficult to implement.
    > Anyone on my programming team who presented a solution that involved
    > multiple readers of a fifo would be encouraged to consider another line of
    > work :-)


    Actually, IIRC, they used this because it was the most portable and
    secure way to do it.

    --
    __Pascal Bourguignon__ http://www.informatimago.com/

    Nobody can fix the economy. Nobody can be trusted with their finger
    on the button. Nobody's perfect. VOTE FOR NOBODY.

  5. Re: Named pipe questions

    "Kurtis D. Rader" wrote in message
    newsan.2005.10.24.03.25.34.82323@skepticism.us...
    [snip]
    > Certainly there are very specialized situations where you might be able
    > to successfully communicate with multiple readers of a single fifo. But
    > they require that the readers read one, and only one, byte from the fifo.
    > Not just one byte per read() but one byte period.


    I could understand one byte per read(), but why "one byte period"?

    Alex



+ Reply to Thread