LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2011, 04:02 AM   #1
mei0fei
Member
 
Registered: Jul 2011
Posts: 38

Rep: Reputation: Disabled
What is meaning that a file is a named pipe (FIFO)?


What is a pipe? and why a file is a named pipe? I am just learning linux.
 
Old 07-12-2011, 05:45 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
See, for example, this Wikipedia page for general information. FIFO stands for "first in, first out", meaning that it's like a pipe: you put in something from one end and you get it out of the other end in the order the contents were put in. An example: open two terminals. From either one, create a fifo (for example in /tmp):
Code:
mkfifo /tmp/testfifo
Now prepare to write data to the fifo in one terminal:
Code:
cat > /tmp/testfifo
Then prepare to read data from the fifo in the other terminal:
Code:
cat /tmp/testfifo
After this, type some lines of text into the first terminal (end lines with Enter), and you'll see them come out from the other terminal reading the fifo. When you're finished, remove the fifo with
Code:
rm /tmp/testfifo
If you write some data to the fifo first (say a few lines) and after that read it (i.e., your reading process is not "on" all the time the writing process is, but is started afterwards), all the (so far) written data is read, so it feels like you were working with ordinary files in that sense. And you're not limited to just playing with two terminals: the point is, you can make programs read and write data to and from the fifo, meaning you can share data between programs using a fifo. Of course you could make a program read the output of another program directly, but in some cases you might want to use a different route instead (fifo or lifo--first in, last out--, for example).

Edit: to be a bit more clear, if process A writes to a fifo (or lifo, depending on which order is required) and process B reads from that fifo (or lifo), and it happens so that it cannot be guaranteed that A is ready to write whenever B is ready to read, or vice versa, then the fifo allows storing information (in order) such that A may write to it when it can, and B may read from it when it can. For example if A produces a lot of data, but B can only handle a bunch at a time, then B can read the data piece by piece from the fifo (or lifo) and in principle not care how much A may have written to it, and on the other hand A can write to the fifo (or lifo) without having to care if B is ready to read the fifo just then.

Last edited by b0uncer; 07-12-2011 at 07:27 AM.
 
Old 07-12-2011, 06:48 AM   #3
mei0fei
Member
 
Registered: Jul 2011
Posts: 38

Original Poster
Rep: Reputation: Disabled
Thanks a lot. I opened two terminals and they worked just like you said.
 
  


Reply



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
[SOLVED] feed text to a file editor from a named pipe kdelover Linux - Newbie 5 04-24-2011 03:20 PM
[SOLVED] How to handle a broken pipe exception (SIGPIPE) in FIFO pipe? zyroot998 Programming 5 03-03-2011 08:10 PM
[SOLVED] Problems with FIFO pipe using a child and parent process mashhype Programming 5 11-22-2010 02:43 AM
Opening a File by using a named pipe akm3 Programming 1 02-17-2009 05:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:09 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration