fifo question

fifo question

Post by Marco Gouvei » Thu, 02 Aug 2001 00:52:41



Hello,

  I'm trying to create a fifo which will store messages for a process to
read later.
  However the writing process should not block until the reading process
gets the message, which is what happens when I create it with mkfifo.

  I know there is a way to do it because there is a pipe created in my
system HP-UX 11, which does it, you can tell by the size, ex:

  # ll pipe0047
  prw-rw----   1 user1      grp1         2088 Jul 31 16:43 pipe0047|

  when I write to it, the process doesn't block:

  # echo "Hello" > pipe0047
  #

  My pipe has exactly the same permissions but the writing processes block
until the data is read. What do I need to do to avoid this ?

  Thanks,

    Marco Gouveia

 
 
 

fifo question

Post by Dan Merc » Thu, 02 Aug 2001 06:23:53




> Hello,

>   I'm trying to create a fifo which will store messages for a process to
> read later.
>   However the writing process should not block until the reading process
> gets the message, which is what happens when I create it with mkfifo.

>   I know there is a way to do it because there is a pipe created in my
> system HP-UX 11, which does it, you can tell by the size, ex:

>   # ll pipe0047
>   prw-rw----   1 user1      grp1         2088 Jul 31 16:43 pipe0047|

>   when I write to it, the process doesn't block:

>   # echo "Hello" > pipe0047
>   #

>   My pipe has exactly the same permissions but the writing processes block
> until the data is read. What do I need to do to avoid this ?

>   Thanks,

>     Marco Gouveia

If you used lsof to examine that fifo you would find that another
process has it open,  probably for update.  A fifo can only
store data if it is open for read and write,  written to and kept open:

   $ mkfifo testfifo
   $ exec 3<>testfifo  # open for u
   $ print -u3 "hello, world"
   $ ll testfifo
   prw-rw-rw-   1 dam        users           13 Jul 31 16:14 testfifo
   $ exec 3<&-         # close read
   $ ll testfifo
   prw-rw-rw-   1 dam        users            0 Jul 31 16:14 testfifo

So,  unless you intend to keep a process around just to keep your fifo
open,  I would suggest you simply use an ordinary file.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

fifo question

Post by Joerg Brueh » Fri, 03 Aug 2001 19:46:32


Hello Marco,


> Hello,

>   I'm trying to create a fifo which will store messages for a process to
> read later.
>   However the writing process should not block until the reading process
> gets the message, which is what happens when I create it with mkfifo.

This is more a programming question than a shell question,
so IMHO "comp.unix.programmer" might offer more answers;
I therefore added a follow-up.

Quote:

>   I know there is a way to do it because there is a pipe created in my
> system HP-UX 11, which does it, you can tell by the size, ex:

>   # ll pipe0047
>   prw-rw----   1 user1      grp1         2088 Jul 31 16:43 pipe0047|

>   when I write to it, the process doesn't block:

>   # echo "Hello" > pipe0047
>   #

>   My pipe has exactly the same permissions but the writing processes block
> until the data is read. What do I need to do to avoid this ?

See the manuals on the "open", "read", and "write" system calls:

By default, FIFOs are operated in "synchronous" mode,
this affects
- "read" (block, until there is data),
- "write" (block if the FIFO buffer is full, AFAIK buffer is 5kB
  typically - see "PIPE_BUF" parameter),
and
- "open" (block until there is a corresponding open for the
  other direction, so that both read and write end are open,
  _unless_ the "open" is with "O_RDWR").

Based on your description, I suspect that your writer process does
not block on writing but already in its "open(..., O_WRONLY)" call.
If that is the case, you either must do the "open (..., O_RDONLY)"
earlier, or the writer should do "open (..., O_RDWR)".

Alternatively, you could use "O_NONBLOCK", but that would add
complexity to the reader process IMO.

In any case, remember the limited amount of data buffered in a FIFO.
You might use "message queues" ("msg..." system calls) which can be
configured for larger size (and also preserve message boundaries)
if the buffer is too small and/or you have more than one reader.

HTH,
Joerg Bruehe

--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
     (speaking only for himself)

 
 
 

fifo question

Post by Ben.Altma » Fri, 03 Aug 2001 23:57:15



> See the manuals on the "open", "read", and "write" system calls:

> By default, FIFOs are operated in "synchronous" mode,
> this affects
> - "read" (block, until there is data),
> - "write" (block if the FIFO buffer is full, AFAIK buffer is 5kB
>   typically - see "PIPE_BUF" parameter),
> and
> - "open" (block until there is a corresponding open for the
>   other direction, so that both read and write end are open,
>   _unless_ the "open" is with "O_RDWR").

When I do a write to a named pipe from the shell it blocks until it is read
from, but when I do a read it always returns right away regardless of the state
of the pipe.

regards,
Ben Altman

 
 
 

1. fifo question

Hello Marco,

This is more a programming question than a shell question,
so IMHO "comp.unix.programmer" might offer more answers;
I therefore added a follow-up.

See the manuals on the "open", "read", and "write" system calls:

By default, FIFOs are operated in "synchronous" mode,
this affects
- "read" (block, until there is data),
- "write" (block if the FIFO buffer is full, AFAIK buffer is 5kB
  typically - see "PIPE_BUF" parameter),
and
- "open" (block until there is a corresponding open for the
  other direction, so that both read and write end are open,
  _unless_ the "open" is with "O_RDWR").

Based on your description, I suspect that your writer process does
not block on writing but already in its "open(..., O_WRONLY)" call.
If that is the case, you either must do the "open (..., O_RDONLY)"
earlier, or the writer should do "open (..., O_RDWR)".

Alternatively, you could use "O_NONBLOCK", but that would add
complexity to the reader process IMO.

In any case, remember the limited amount of data buffered in a FIFO.
You might use "message queues" ("msg..." system calls) which can be
configured for larger size (and also preserve message boundaries)
if the buffer is too small and/or you have more than one reader.

HTH,
Joerg Bruehe

--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
     (speaking only for himself)

2. Force IRQ Settings?

3. FIFO Question

4. lpd and remote printing

5. Quick FIFO question

6. best apache+python module?

7. newie: fifo question

8. CDROM major/minor #s

9. Got a fifo question

10. FIFO question

11. FIFO Question

12. a question about fifo

13. FIFO pipe buffer questions