Hot answers tagged

47 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
33 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
32 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
  • 48.3k
25 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
  • 71.3k
25 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
  • 109k
17 votes

A virtual file containing the concatenation of other files

wrote a fuse driver today, if someone is interested in the fuse solution (the device mapper as well as the nbd-solution above will create block devices not regular files - which will break, if you ...
Peter's user avatar
  • 181
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,071
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

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
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
  • 327k
13 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
  • 33.5k
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

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
11 votes
Accepted

Program output redirection

This supposed program will write to file descriptor number you specified. consider the following hello world program: #include <stdio.h> main() { ssize_t i = 0 ; printf ("hello world\n") ...
Archemar's user avatar
  • 31.4k
11 votes
Accepted

How to implement "generators" like $RANDOM?

ksh93 has disciplines which are typically used for this kind of thing. With zsh, you could hijack the dynamic named directory feature: Define for instance: zsh_directory_name() { case $1 in (n)...
Stéphane Chazelas's user avatar
11 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
  • 15.7k
11 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,718
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
  • 50.5k
10 votes

Program output redirection

The numbers represent file descriptors (handles to files that have been opened). The shell usually has 3 set automatically, 0 - stdin 1 - stdout 2 - stderr But further files can be opened, and the ...
X Tian's user avatar
  • 10.4k
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,016
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.6k
8 votes

Program output redirection

Those numbers are file descriptors. As you noted, there are several that are created automatically. As other files or file-like things are opened, they will get other numbers. The numbers that are ...
Eric Renouf's user avatar
  • 18.3k
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
  • 135k
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
  • 327k

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