FIFO files

This is a discussion on FIFO files within the C Programming forums, part of the General Programming Boards category; Hi! I was just thinking about this for quite a while. Why was it necessary to create fifo files and ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    2

    FIFO files

    Hi! I was just thinking about this for quite a while. Why was it necessary to create fifo files and organize all writng and reading stuff by means of it? I mean we can achieve the same result using just normal files and in most cases it is more useful?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Belka View Post
    Hi! I was just thinking about this for quite a while. Why was it necessary to create fifo files and organize all writng and reading stuff by means of it? I mean we can achieve the same result using just normal files and in most cases it is more useful?
    Because that's the normal way we deal with information and data.

    Welcome to the forum, Belka!

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    2
    Quote Originally Posted by Adak View Post
    Because that's the normal way we deal with information and data.

    Welcome to the forum, Belka!
    Tnxs))) But my curiosity isnt satisfied))

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Belka View Post
    Tnxs))) But my curiosity isnt satisfied))
    Ask yourself, "how do I write information?", and "how do I read it?".

    Contrast that with the few things you do, in LIFO order.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,279
    Do you mean FIFO files like you create with the mkfifo() function? If so:

    Quote Originally Posted by Belka View Post
    Why was it necessary to create fifo files and organize all writng and reading stuff by means of it?
    This question is like asking "why would you ever use a queue or linked list when you could just use a hash table?". Different problems and their solutions have different needs.

    FIFO files are used as a method of inter-process communication (IPC). It allows two separate processes to share data. FIFOs work, by definition, in a "first in, first out" fashion, so data always comes out in the order it went in. That is often the way we want to work with data, processing it in order. There are other mechanisms that allow for random access of data, such as a regular file, but often we don't need, or don't want that "feature". Also, FIFOs have the property that, once you read data from a FIFO, it's gone, it can't be read again. That's because FIFOs are actually streams of data, not files in the typical sense. They merely look like files, having an entry in the file system, like /home/username/my_fifo. That just gives a easy way for the processes to access the FIFO. That provides one huge benefit. Because they aren't regular files, they don't use the hard drive, they only exist in memory. That means they are much, much faster.

    Quote Originally Posted by Belka View Post
    I mean we can achieve the same result using just normal files and in most cases it is more useful?
    "In most cases" is a spurious claim at best, usefulness is very subjective and is a case-by-case issue. Yes, you can get the same results with normal files, but with other side effects. If you have a very large amount of data to share between processes, a regular file would use up tons of disk space, since regular files don't dispose of the data after it's read. Yes, hard drives are cheap, but why use up all that space if you don't need to. Sure, you could monitor the size of the file and "trim" it or reset it once it gets too large, but that's a lot of extra work when you could just use a FIFO, and you still need a method of IPC to keep one process from erasing data from the file when the other one is trying to write to it.

    In summary:
    It's never "necessary" to use FIFOs, there are other methods, but in some circumstances, FIFOs are the best/easiest choice. Sometimes regular files are too slow, and can be hard to manage if you don't want to store the data permanently and you don't need/want the random access feature.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    With regular files you also would need to watch the file to see if something was written, a fifo is a pipe so when the writing process is done the result appears in the reading process (read and writes blocks).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FIFO problemss.. Please help? =)
    By c3jcarmy in forum C Programming
    Replies: 1
    Last Post: 11-25-2011, 04:04 PM
  2. Help with FIFO queue
    By Martin_T in forum C Programming
    Replies: 10
    Last Post: 11-08-2009, 09:30 AM
  3. working with FIFO files
    By icebabe in forum C Programming
    Replies: 6
    Last Post: 05-06-2006, 11:35 AM
  4. FIFO list
    By Lillian176 in forum C Programming
    Replies: 4
    Last Post: 04-13-2003, 10:45 PM
  5. FIFO help
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-15-2002, 11:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21