Does write()ing to a pipe ever block?

Does write()ing to a pipe ever block?

Post by Alex Farbe » Sat, 26 Feb 2000 04:00:00



Hi,

here is another question: what happens if you write()
much data to an unnamed pipe, but read() seldom or
never. Will write() block?

The Stevens book mentiones PIPE_BUF which is how many
bytes a process/thread can write at once (atomic). But
I can not find any other limits on pipes. There is no
EFULL or something in the "man 2 write" either...

Thank you very much
Alex

PS: I have a program with two threads: one thread takes
    strings, received by readline and write()s them to a
    pipe. The second thread select()s on that pipe and
    read()s. Would you lock a mutex bevor write()ing?

 
 
 

Does write()ing to a pipe ever block?

Post by Andrew Giert » Sat, 26 Feb 2000 04:00:00


 Alex> Hi,
 Alex> here is another question: what happens if you write() much data
 Alex> to an unnamed pipe, but read() seldom or never. Will write()
 Alex> block?

yes. (Unless the pipe has been set to nonblocking mode with fcntl.)

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

1. AIX 3.1.5: open()'ing named pipe doesn't block

I'm running AIX 3.1.5 on an RS/6000 320.  I've created a named pipe
by typing 'mknod fifo p'.  I wrote a program which does an
open("fifo", O_WRONLY, 0644).  The open is supposed to block until
another process opens the pipe for reading, but it does not block.
My program opens it, writes to it and closes it, even tho' no one else
is reading from it.  You can verify that open()'s don't block without
even writing a program by creating one and cat'ing it.  The cat just
returns instead of blocking.

I've called this in to IBM, but their first response was "Fax us code
which reproduces the problem," so who knows how long it will take to
deal with this.  My question is:  Has anyone else seen this and called
it in?  Is there an existing fix, or a workaround, or anything that
might help?  It's not a mission-critical application I'm working on
(I want a random .signature :-), but I'd like to resolve it soon anyway.

a T d H v A a N n K c S e.
--
JB Christy                              "Don't worry about her.  She's still
QA Engineer, ONTOS, Inc.                 upset because somebody dropped a

uunet!uupsi!ontos!christy                   -- from the movie "Beetlejuice"

2. Update Re: Need help setting eth1:0

3. write()ing to a blocking socket

4. 64-bit jiffies, a better solution

5. pipe write() blocks even though select() indicates writable

6. Bad Yellow Dog Linux! Bad! Bad!

7. Non-blocking writing on a Named pipe

8. entry point

9. select() and write() behavior with non-blocking named-pipe

10. select(), non blocking writes to pipes and EAGAIN

11. [2.5] Non-blocking write can block

12. O_DIRECT write to file by block-aligned, block-multiple buf fails?

13. incomplete socket writes (when write blocks)