Find the answer to your Linux question:
Results 1 to 4 of 4
Hi : Is there a way to figure out the following about a linux FIFO. 1. size - how much data in it at any given time. 2. capacity - ...
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Posts
    22

    Linux FIFO. Determining Size, Reaches capacity

    Hi :
    Is there a way to figure out the following about a linux FIFO.

    1. size - how much data in it at any given time.
    2. capacity - what is the max it can hold


    What does the fifo do when it reaches its capacity? Suppose the reader isn't keeping up with the writer, can the writer figure this out and react. Will the writer slow down when it is full and only write at the rate that it is being read?

    Thanks
    Bandeg

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    1. size - how much data in it at any given time.
    I am unaware of any obvious way to know this.
    What does the fifo do when it reaches its capacity?
    Unless specific steps are taken, the writer will wait until there is room, write the data, and continue its own processing. Which I gather is not what you want.
    Will the writer slow down when it is full and only write at the rate that it is being read?
    Effectively, yes. The writer will wait until there is room for its data in the FIFO before continuing its processing.
    Suppose the reader isn't keeping up with the writer, can the writer figure this out and react.
    Yes. The writer can open the FIFO in non-blocking mode and then do its processing in a loop in which it does a select() before doing the write(), and only doing the write() if the select() said that the FIFO was ready to be written to.

    For further info, do this at the command line:
    Code:
    man 2 select
    If man pages are not installed on your system, google for this.
    Code:
    man select linux
    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    22
    Thanks for the execellent info. One thing that I also can do is check the return from the write() to see if it wrote all the data. If not, can I consider the fifo full?

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Thanks for the execellent info. One thing that I also can do is check the return from the write() to see if it wrote all the data. If not, can I consider the fifo full?
    That's a possibility, but I wouldn't count on it.

    If, when you get back from the select(), you do not get an indication that the FIFO may be written to, then you can consider the FIFO full. Otherwise, you should keep writing.

    Your select() loop should keep looping until the select() indicates that no I/O can be done on any of the file descriptors of interest. Of course, if you run out of data to write to the FIFO, you should remove that file descriptor from the list of file descriptors of interest, until you have more data to write.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...