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
35 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
33 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
  • 49.6k
27 votes
Accepted

Prevent automatic EOFs to a named pipe, and send an EOF when I want it

As others have indicated, the reader of a pipe receives EOF once there are no writers left. So the solution is to make sure there is always one writer holding it open. That writer doesn't have to send ...
phemmer's user avatar
  • 72.3k
26 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
  • 111k
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

How to get an average pipe flow speed

With pv 1.2.0 (December 2010) and above, it's with the -a option: Here with both current and average, line-based: $ find / 2> /dev/null | pv -ral > /dev/null [6.28k/s] [70.1k/s] With 1.3.8 (...
Stéphane Chazelas's user avatar
16 votes
Accepted

“Leaky” pipes in linux

Easiest way would be to pipe through some program which sets nonblocking output. Here is simple perl oneliner (which you can save as leakybuffer) which does so: so your a | b becomes: a | perl -...
Matija Nalis's user avatar
  • 3,176
16 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
14 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
  • 37.2k
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
  • 339k
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
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
12 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,771
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

Why doesn't file redirection to and from a named pipe work, but piping to cat does?

This is because the netcat command has not even started yet! The shell when trying to open the fifo for input will block. Try strace cat >fifo <fifo and you will see nothing. Instead use, ...
meuh's user avatar
  • 51.9k
9 votes

Can I increase the system pipe buffer max?

Your command changes the maximum buffer size, not the default one. From the pipe(7) manpage: /proc/sys/fs/pipe-max-size (since Linux 2.6.35) The maximum size (in bytes) of individual pipes ...
xhienne's user avatar
  • 17.9k
9 votes
Accepted

How to read a webcam that is already used by a background capture?

Do this: sudo modprobe v4l2loopback devices=1 If you get similar error like modprobe: FATAL: Module v4l2loopback not found in directory /lib/modules/4.6.0-kali1-amd64, just install v4l2loopback-dkms ...
林果皞's user avatar
  • 5,206
8 votes

Read named pipe once every time input is written

In your case, you can do simply: tail -f $pipe | sh & no need for loops.
Gnudiff's user avatar
  • 975
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
  • 141k
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
  • 339k
7 votes
Accepted

Read named pipe once every time input is written

One way to do it: #! /usr/bin/env bash pipe=/path/to/pipe [ -p "$pipe" ] || mkfifo -m 0600 "$pipe" || exit 1 while :; do while read -r cmd; do if [ "$cmd" ]; then printf '...
Satō Katsura's user avatar
7 votes

Can you scp, sftp, or rsync, a pipe?

It is not exactly "pipe", but you can basically tell scp to copy specific FD (which can be pipe) from your host to the other. Simple bash command like this: (scp does not work as it needs a size in ...
Jakuje's user avatar
  • 21.4k
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
Accepted

Print current number of bytes in a pipe

Note that when you do: cmd > named-pipe While there's no other process that has the pipe open for reading, it's the open() that hangs. That open() above is done by the shell, cmd is not even ...
Stéphane Chazelas's user avatar

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