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)