LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-02-2011, 09:44 AM   #1
abhishekbatra
LQ Newbie
 
Registered: May 2008
Location: Delhi, India
Distribution: Debian, Ubuntu, Kubuntu
Posts: 27
Blog Entries: 1

Rep: Reputation: 0
Data queued in a named pipe.


Is there any way to find out how much data is queued in/written to a POSIX named pipe?

Thanks,
Abhishek
 
Old 12-03-2011, 09:29 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Other than reading the pipe, not that I know of.

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.
 
1 members found this post helpful.
Old 12-03-2011, 09:51 AM   #3
abhishekbatra
LQ Newbie
 
Registered: May 2008
Location: Delhi, India
Distribution: Debian, Ubuntu, Kubuntu
Posts: 27
Blog Entries: 1

Original Poster
Rep: Reputation: 0
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?
 
Old 12-03-2011, 12:51 PM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by abhishekbatra View Post
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 View Post
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.
 
  


Reply

Tags
fifo, named, pipe


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
execvp with a named pipe bahwilliams Programming 2 02-01-2007 03:16 PM
What is a named pipe ronzoid Linux - General 1 01-18-2006 04:30 PM
unlinking named pipe sahel Programming 1 01-12-2006 04:45 AM
unlinking named pipe sahel Programming 1 01-09-2006 10:36 PM
named pipe sahel Programming 1 01-09-2006 08:29 AM


All times are GMT -5. The time now is 01:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration