I have a fifo opened as RDWR(for communicate process-process) and pipes(process-thread), how can I understand when I reach pipes or fifos limit? When I try to write more than 64 KB it just wait in write().
Asked
Active
Viewed 1,663 times
4
-
4That how pipes work. If the pipe gets full when you write to it, `write` will block until data is "removed" from the pipe. – Some programmer dude May 07 '16 at 14:20
-
4Open non-blocking and test the result of `write`. – too honest for this site May 07 '16 at 14:20
1 Answers
5
You need to use non-blocking mode:
pipe2(fds, O_NONBLOCK);
Or if you need to do it after the pipe was created:
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
Now when you read or write and the operation cannot complete immediately, it will return. You can then use select()
or poll()
to find out when reading or writing is possible again (or you can just busy-wait).

John Zwinck
- 239,568
- 38
- 324
- 436
-
3And it will return `-1` and set `errno` to `EAGAIN` — POSIX [`write()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html) says: _A write request for {PIPE_BUF} or fewer bytes shall have the following effect: if there is sufficient space available in the pipe, write() shall transfer all the data and return the number of bytes requested. Otherwise, write() shall transfer no data and return -1 with errno set to [EAGAIN]._ – Jonathan Leffler May 07 '16 at 17:22
-
2I should note that the description I quoted applies specifically to a pipe or FIFO with the `O_NONBLOCK` flag set — read the rest of the specification for the behaviour under other circumstances. – Jonathan Leffler May 07 '16 at 19:10