Skip to main content
50 votes
Accepted

Linux named pipes: not as FIFO as thought

This has nothing to do with FIFO semantics of pipes, and doesn’t prove anything about them either way. It has to do with the fact that FIFOs block on opening until they are opened for both writing and ...
Stephen Kitt's user avatar
37 votes

Linux named pipes: not as FIFO as thought

Pipes are first-in first-out. Your problem is that you misunderstand when the “in” happens. The “in” event is writing, not opening. Removing useless punctuation, your code is: echo a > fifo & ...
Gilles 'SO- stop being evil''s user avatar
34 votes
Accepted

Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?

Yes, it's equivalent, but obviously only if you tell mknod to actually create a FIFO, and not a block or character device (rarely done these days as devtmpfs/udev does it for you). mkfifo foobar # ...
frostschutz's user avatar
  • 52.1k
27 votes
Accepted

How does a FIFO (named pipe) differs from a regular pipe (unnamed pipe)?

"Named pipe" is actually a very accurate name for what it is — it is just like a regular pipe, except that it has a name (on a filesystem). A pipe — the regular, un-named ("anonymous") one used in ...
derobert's user avatar
  • 113k
17 votes

What is the purpose of using a FIFO vs a temporary file or a pipe?

APUE says “FIFOs can be used to duplicate an output stream”, it doesn’t say that FIFOs actually duplicate the output stream. As you point out, the duplication is done by tee in the example. mkfifo ...
Stephen Kitt's user avatar
17 votes
Accepted

Change buffer size of named pipe

A fifo file is just a type of file which when opened for both reading and writing instantiates a pipe like a pipe() system call would. On Linux at least, the data that transits though that pipe is ...
Stéphane Chazelas's user avatar
16 votes
Accepted

Under what conditions exactly does SIGPIPE happen?

Your example is using a fifo not a pipe, so is subject to fifo(7). pipe(7) also tells: A FIFO (short for First In First Out) has a name within the filesystem (created using mkfifo(3)), and ...
A.B's user avatar
  • 39.5k
14 votes
Accepted

Named pipes, file descriptors and EOF

It has to do with the closing of the file descriptor. In your first example, echo writes to its standard output stream which the shell opens to connect it with f, and when it terminates, its ...
Kusalananda's user avatar
  • 356k
13 votes
Accepted

How to save an output of airodump-ng to a file?

Check man airodump-ng. You want the -w option. airodump-ng -w myOutput --output-format csv mon0 Generates a .csv file of the screendump with the output from airodump-ng one line per station.
bu5hman's user avatar
  • 4,851
12 votes
Accepted

Write to FIFO only if it exists

According to the BASH manual: -p file True if file exists and is a named pipe (FIFO). So: if [[ -p /tmp/my_fifo ]]; then # commands to execute fi The question has the tag, bash. In context, ...
Christopher's user avatar
  • 16.3k
12 votes
Accepted

Reading a named pipe: tail or cat?

When you do: cat fifo Assuming no other process has opened the fifo for writing yet, cat will block on the open() system call. When another process opens the file for writing, a pipe will be ...
Stéphane Chazelas's user avatar
11 votes
Accepted

How to cat named pipe without waiting

To prevent cat from hanging in the absence of any writer (in which case it's the opening of the fifo, not reading from it, that hangs), you can do: cat 0<> "$my_named_pipe" <"$my_named_pipe" ...
Stéphane Chazelas's user avatar
10 votes
Accepted

Understanding file descriptors and pipes resulting from `cat <(<command>)`

So, a process substitution like outer <(inner) makes the output of inner available as a named file that outer can then open. That could be done through named pipes (FIFOs), similarly to something ...
ilkkachu's user avatar
  • 148k
8 votes

Named pipes, file descriptors and EOF

There's not much to it: when there are no writers to the pipe, it looks closed to readers, i.e. returns EOF when read and blocks when opened. From the Linux man page (pipe(7), but see also fifo(7)): ...
ilkkachu's user avatar
  • 148k
8 votes
Accepted

Split output and rejoin again with named pipes on linux

mkfifo thepipe cmd3 <( cmd1 | tee thepipe ) <( cmd2 thepipe ) This uses a named pipe, thepipe, to transfer data between tee and cmd2. Using your diagram: cmd1 ---(tee)---(thepipe)--- cmd2 ---&...
Kusalananda's user avatar
  • 356k
8 votes
Accepted

Using make variable in bash scripting as part of a makefile command

The problem is that /bin/sh, the default shell used by Make, is dash on Ubuntu, and your Makefile relies on bash features (specifically, arrays — the error is in the FIFOS+= line). You can specify the ...
Stephen Kitt's user avatar
7 votes

How to send commands to fbi over SSH?

To display an image, fbi needs access to the TTY. So, you need to use -T 1: fbi -d /dev/fb0 -T 1 zxcv.png If you get access /dev/tty1: Permission denied, you can run the command with sudo. ...
Daniel's user avatar
  • 171
7 votes
Accepted

grep --exclude option doesn't always skip named pipes

It seems grep still opens files even if the regex tells it to skip them: $ ll total 4.0K p-w--w---- 1 user user 0 Feb 7 16:44 pip-fifo --w--w---- 1 user user 4 Feb 7 16:44 pip-file lrwxrwxrwx 1 ...
greppy mcgrepface's user avatar
6 votes

How does a FIFO (named pipe) differs from a regular pipe (unnamed pipe)?

I think you're getting mixed up between shell syntax for pipelines vs. the underlying Unix systems programming. A pipe / FIFO is a type of file that isn't stored on disk, but instead passed data from ...
Peter Cordes's user avatar
  • 6,690
6 votes
Accepted

How can I know whether writing to a named pipe would block?

If you want to write to the pipe, only if there are some process that has opened it for reading, you could open it for writing in non-blocking mode. With GNU dd: echo Hello | dd oflag=nonblock of=...
Stéphane Chazelas's user avatar
6 votes

What characterizes a file in Linux/Unix?

TL;DR a file is an object on which you can perform some or all of basic operations - open,read,write,close - and has metadata stored in an inode. file descriptors are references to those objects open ...
Sergiy Kolodyazhnyy's user avatar
6 votes
Accepted

How to check for presence of named pipe on the file system

You need to use the -p construct to see if the file is of type named pipe. It works with the standard test [ (POSIX compliant) and the extended test operators [[ ( bash/zsh specific ) if [[ -p "$...
Inian's user avatar
  • 13.1k
6 votes
Accepted

Reading n lines at a time from a named pipe in Ubuntu

You want to keep the fifo open on the reading side. One way is to let bash keep an open file descriptor to it. #!/bin/bash mkfifo pipe ls > pipe & exec 8< pipe r2(){ read -ru 8 fn1 ...
icarus's user avatar
  • 19.1k
6 votes
Accepted

Bash named pipes, parallel commands and exit status

To get the exit status of an asynchronous command, you use wait on its pid: #!/bin/bash - pipe=$(mktemp -u) || exit mkfifo -m 600 -- "$pipe" || exit dd if=/dev/zero of="$pipe" bs=...
Stéphane Chazelas's user avatar
6 votes
Accepted

Why SIGTSTP (^Z/Ctrl-Z/suspend) doesn't work when process blocked redirecting write into a FIFO/pipe not open for reading yet? And what to do then?

echo is a builtin command in virtually all shells including bash. In: cmd > fifo It's the opening of the fifo by the shell to perform the redirection that blocks. If cmd is an external command, ...
Stéphane Chazelas's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible