Hot answers tagged

39

UNIX domain sockets and FIFO may share some part of their implementation but they are conceptually very different. FIFO functions at a very low level. One process writes bytes into the pipe and another one reads from it. A UNIX domain socket has the same behaviour as a TCP/IP socket. A socket is bidirectional and can be used by a lot of processes ...


33

You're not seeing any performance benefit because you're not actually hitting disk when using a file - the data's on its way to the disk, but your execution thread doesn't need to wait for it to land there, so you're not actually seeing the speed penalty of hitting the disk. If you want to wait for the disk operation to complete to see how much slower that ...


29

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 # same difference mknod foobar p In strace it's identical for both commands: mknod("foobar", S_IFIFO|0666) = 0 So in terms of syscalls, mkfifo is ...


23

cat keeps reading until it gets EOF. A pipe produces EOF on the output only when it gets EOF on the input. The logging daemon is opening the file, writing to it, and keeping it open — just like it does for a regular file — so EOF is never generated on the output. cat just keeps reading, blocking whenever it exhausts what's currently in the pipe. You can try ...


21

"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 some-command | grep pattern is a special kind of file. And I do mean file, you read and write to it just like you do every other file. Grep doesn't really care¹ ...


20

On Linux-based operating systems, that can be done with network block devices or device mapper devices. The file you obtain is a block device. With nbd: ln -s /path/to/first-file file.0 ... ln -s /path/to/last-file file.19 nbd-server -C /dev/null -m 127.0.0.1:12345 file sudo nbd-client localhost 12345 /dev/nbd0 (the concatenation is /dev/nbd0). With ...


16

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 anything, just hold it open. Since you're using a shell script, the simplest solution is to tell the shell to open the pipe for writing. And then close it ...


15

Since Linux kernel 2.6.35, you can increase the size of a pipe with the F_SETPIPE_SZ fnctl(). Non-privileged users are limited to values between 0 and the current value of the fs.pipe-max-size sysctl (1 MiB by default). The value you use should be greater than 64 KiB and be a power of 2. So you could do: perl -MFcntl -e 'fcntl(STDIN, 1031, 1048576) or die ...


15

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 (October 2012) and newer, you can also use -F/--format with %a: $ find / 2> /dev/null | pv -lF 'current: %r, average: %a' > /dev/null current: [4.66k/s], ...


14

ps lists bash as the running process because the bash process is blocked trying to open the fifo /tmp/in2 before spawning the cat command. Since bash is responsible for handling your redirect(> /tmp/in2), it must first open /tmp/in2 so that it can later use the dup2 system call to change the STDOUT of the cat command to the file descriptor for /tmp/in2. ...


14

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 -MFcntl -e \ 'fcntl STDOUT,F_SETFL,O_NONBLOCK; while (<STDIN>) { print }' | b what is does is read the input and write to output (same as cat(1)) but the ...


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 ...


12

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 instantiated and open() will return. cat will call read() in a loop and read() will block until some other process writes data to the pipe. cat will see end-of-file (...


12

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 descriptor is closed (by the shell). On the receiving end, the shell, which reads input from its standard input stream (connected to f) reads ls, runs ls and then ...


11

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 want to use the resulting output directly with video editing software or other tools which are not prepared to read from a block device directly) https://github....


11

THe SSHFS filesystem is built on top of the SFTP protocol. SFTP provides only facilities to manipulate files in “classical” ways; the client makes a request to the server (list a directory, upload a file, etc.), and the server responds. There is no facility in this protocol for the server to spontaneously notify the client that something has happened. This ...


11

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") ; i = write( 5 , "Bonjour Monde\n", 14 ) ; printf ("%d octet dans 5\n", (int) i) ; } compile it me@mybox:~/tmp7$ make hw cc hw.c -o hw now a ...


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:...


10

No disk i/o (except perhaps when navigating through the filesystem to open the fifo file.) From the Linux fifo(7) man page: A FIFO special file (a named pipe) is similar to a pipe, except that it is accessed as part of the filesystem. [...] When processes are exchanging data via the FIFO, the kernel passes all data internally without writing it ...


10

This is just shell variable expansion by bash. In this context whatever is between the curly braces will be iterated and expanded into the expression. $ echo var{1,2,3,4} var1 var2 var3 var4 $ echo var{1..10} var1 var2 var3 var4 var5 var6 var7 var8 var9 var10


10

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 numbers increment.


10

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) case $2 in (incr) reply=($((++incr))) esac esac } And then you can use ~[incr] to get an incremented $incr each time: $ echo ~[incr] 1 ...


10

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, for example, nc -k -l 4458 -v <>fifo >&0 which opens the fifo for read and write as stdin, and then dups it to stdout. Tracing the full bash ...


10

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.


10

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 is opened using open(2). Any process may open a FIFO, assuming the file permissions allow it. The read end is opened using the O_RDONLY flag; ...


9

To delete all FIFOs in the current directory and all sub-folders use find . -type p -delete To delete FIFOs only in the current directory use find . -maxdepth 1 -type p -delete


9

No, it's echo test > "$tmppipe" # BTW, you've got the quotes in the wrong places that hangs. More precisely, it's the shell opening the pipe for writing before running echo. pipe are inter-process communication mechanisms, they are to be used between processes running concurrently. Here, the open(WR_ONLY) (>) will block until another process does an ...


9

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, the usage of [[ and ]] is specific to BASH. (Tangentially, [[ and ]] also work with zsh and the Korn shell.) See BashFAQ/031. Portable scripts should be ...


8

There's quite a good discussion of this here: http://www.slideshare.net/divyekapoor/linux-kernel-implementation-of-pipes-and-fifos So far as I can see, both from the presentation slides, and the source @ http://lxr.free-electrons.com/source/fs/pipe.c - fifo's are implemented as a wrapper around pipe's, and pipe's themselves are implemented via the pipefs ...


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