ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
When using sockets (for example, a socket pair created using socketpair(2)), one can use recv(descriptor,buffer,buffersize,MSG_NOWAIT|MSG_PEEK) to read but not consume already buffered data from the socket. It will not work with named pipes, however; only with sockets.
Thank you for the helpful reply. For the problem I had at hand I only needed to know when the pipe is empty, so the reader can stop reading. After your conformation and going through the manpage again I guess a call to read(int fildes, void *buf, size_t nbyte) is enough for that.
But just out of curiosity and for possible utility, is there a way to peek into the underlying kernel data structures to find out the fifo size, if anyone knows that?
Thank you for the helpful reply. For the problem I had at hand I only needed to know when the pipe is empty, so the reader can stop reading. After your conformation and going through the manpage again I guess a call to read(int fildes, void *buf, size_t nbyte) is enough for that.
You may wish to open the pipe nonblocking (or set it nonblocking using fcntl(descriptor,F_SETFL,O_NONBLOCK)), so the call will return immediately if there is no data to read from the pipe.
Quote:
Originally Posted by abhishekbatra
But just out of curiosity and for possible utility, is there a way to peek into the underlying kernel data structures to find out the fifo size, if anyone knows that?
Only if using kernel 2.6.35 or later. Then, you have fcntl(descriptor,F_GETPIPE_SZ) to find out the capacity of the pipe (if the descriptor refers to a pipe), and fcntl(descriptor,F_GETPIPE_SZ,size) to set the pipe capacity. If setting a pipe capacity that is not a multiple of page size (sysconf(_SC_PAGESIZE)), the kernel will round it upwards to the next multiple of page size.
An userspace application may adjust the pipe capacity freely between one page (sysconf(_SC_PAGESIZE) bytes) and /proc/sys/fs/pipe-size-max bytes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.