5

As far as I understand, named pipes are not written to disk but are stored in memory. Here's how I created a named pipe -

$ mkfifo pipe21
$ grep "simple" SimpleDoc.txt > pipe21 &
[1] 2775
$ cat pipe21
Very simple doc that contains plaintext. 
[1]+  Done                    grep --color=auto "simple" SimpleDoc.txt > pipe21

After this, I restarted my system. However, even after the restart, I see pipe21 in my current directory. Why is that?

2 Answers 2

12

A named pipe is part of the filesystem. Anything that has a filename is part of the filesystem. If that happens to be a filesystem in persistent storage (i.e. on disk), then it survives a system reboot.

A filesystem entry for a named pipe just has a name, the usual metadata (time, permissions, etc.), and a flag that says “this is a named pipe”. The data that goes through the pipe doesn't go to the filesystem. But the named pipe itself is in the filesystem.

10

No they're written to disk. The command mkfifo pipe21 creates the corresponding device on your filesystem. Often times these devices are kept under /dev but named pipes (aka. FIFOS) don't necessarily have to be kept in this directory.

excerpt from wikipedia article

The named pipe can be deleted just like any file:
$ rm my_pipe

Example

Make a FIFO:

$ pwd
/home/saml

$ mkfifo pipe21

Check out the FIFO device:

$ ls -l | grep pipe
prw-rw-r--   1 saml saml        0 Jul 24 12:22 pipe21

$ file pipe21 
pipe21: fifo (named pipe)

Delete the device:

$ rm pipe21 

$ ls -l | grep pipe

References

2
  • /dev does not have to contain all of the devices on the system -- it is perfectly legal to have them elsewhere.
    – Chris Down
    Commented Jul 24, 2013 at 16:18
  • @ChrisDown - thanks I forgot that they can be created in other directories such as /tmp or where ever else. Updated my answer, thanks again for the feedback!
    – slm
    Commented Jul 24, 2013 at 16:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .