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 ...
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 & ...
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
# ...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
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, ...
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 ...
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"
...
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 ...
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)):
...
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 ---&...
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 ...
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.
...
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 ...
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 ...
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=...
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 ...
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 "$...
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
...
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=...
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, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
fifo × 260pipe × 109
bash × 64
linux × 33
shell-script × 29
shell × 27
io-redirection × 18
file-descriptors × 15
ipc × 14
mkfifo × 14
process-substitution × 10
read × 9
stdin × 9
cat × 8
netcat × 8
files × 7
process × 7
stdout × 7
socket × 7
systemd × 6
python × 6
c × 6
ffmpeg × 6
tail × 6
buffer × 6