Should be pretty easy to confirm/deny that suspicion and see if it's worth going down the rabbit hole, no?
strace -e open -o >(grep O_DIRECT) ./myprogramShould be pretty easy to confirm/deny that suspicion and see if it's worth going down the rabbit hole, no?
strace -e open -o >(grep O_DIRECT) ./myprogram -o >(grep O_DIRECT)
This is cool. Never seen it (but it makes sense.) diff <(cmd a) <(cmd b)
is also very handy. $ ls <(echo A)
/dev/fd/63
$ cat <(echo A)
A
So diff <(command1) <(command2)
becomes diff /dev/fd/62 /dev/fd/63More: https://www.gnu.org/software/bash/manual/html_node/Process-S...
I'm also pretty sure it originated in ksh, not bash.
you might want to read into redirection on the commandline, it's amazingly powerful
$ echo <(echo 1) <(echo 2)
/dev/fd/63 /dev/fd/62
The shell spawns two commands connected to pipes, then replaces those with a file that represents the other (read) side of that pipe.The command above with >(grep something) does the same thing, just with the other end of a pipe.
This is explained in more detail here:
https://askubuntu.com/questions/172982/what-is-the-differenc...
# cat <(ls -l /proc/self/fd/)
total 0
lrwx------ 1 root root 64 Jan 12 15:02 0 -> /dev/pts/0
l-wx------ 1 root root 64 Jan 12 15:02 1 -> pipe:[20519634]
lrwx------ 1 root root 64 Jan 12 15:02 2 -> /dev/pts/0
lr-x------ 1 root root 64 Jan 12 15:02 3 -> /proc/23611/fd/
# ls -l /proc/self/fd/ | cat -
total 0
lrwx------ 1 root root 64 Jan 12 15:02 0 -> /dev/pts/0
l-wx------ 1 root root 64 Jan 12 15:02 1 -> pipe:[20518265]
lrwx------ 1 root root 64 Jan 12 15:02 2 -> /dev/pts/0
lr-x------ 1 root root 64 Jan 12 15:02 3 -> /proc/23621/fd/https://github.com/coreutils/coreutils/blob/master/src/cat.c...
It’s an intentional design decision.
In my case I'm using it to describe the use of a kernel pipe object. In your case, you are using it to describe the higher-level concept of connection from one processes stdout to another process's stdin (or something along those lines).
What it looks like is ls having its stdout (fd 1) directed to a pipe.
| is the pipe operator in sh for doing a shell "pipeline". However, the parent comment is referring to a linux pipe as in pipe(7) [0].
One easy way to see this is with the following:
$ ls -l <(echo foo)
lr-x------ 1 user group Jan 12 01:23 /proc/self/fd/16 -> 'pipe:[2937585]'
As you can see, that command created a fd (16) which referred to a pipe (pipe:[2937585]).Those file descriptors were created using the pipe(2)[1] call by the shell, so it seems fine to refer to them to pipes.
I'll also note that <() / >() are _not_ using the "redirection operator". They're actually distinct operators for "process substitution"[2] in bash terminology. They look similar to redirects, but they're not the same operator, so that stack overflow answer isn't really relevant.
[0]: http://man7.org/linux/man-pages/man7/pipe.7.html
In case of unnamed pipe the fds just exist as long as the process is running, then it disappears. Point is it’s irrelevant what you refer to as pipe, at the end of the day some file-like object is either written to or read from. And really, that file-like object is actually just a buffer.
A quick search says that Windows has support for named pipes as an IPC mechanism [1], but I’ve never used them. But this is a Windows API. I am not aware for any way to do this with plain cmd.exe. You’re not the first to ask though... [2]
[1] https://docs.microsoft.com/en-us/windows/win32/ipc/named-pip...
[2] https://superuser.com/questions/430466/in-windows-can-i-redi...
Even the echo example hints, that the created pipe has a name, and that name is then simply passed as the argument to the command.
Well, the echo example shows that the pipe is reified at /dev/fd/63 (or /dev/fd/62 for the other pipe).
That's not a named pipe. It's a file descriptor identified by the integer that defines it, accessed under the /dev/fd listing of all file descriptors.
So, to sort of answer your questions:
> How does diff know to read from those two pipes?
They're two different pipes. Diff takes two arguments. Each argument is one of the pipes.
> (implied) Is there such a thing as an anonymous pipe, in any context?
Not if you consider /dev/fd/id-of-pipe to be a name. The operating system lists them all there. But usually you would use a named pipe if you wanted to be able to know the name, so that you could find it again if you didn't already have a reference to it. If you jammed your finger into my chest, I would be there, and my physical form would block the passage of your finger analogously to how an anonymous pipe nevertheless exists as an entry (two entries?) in /dev/fd. But that wouldn't tell you my name in the conventional sense, even though it would be a valid and unambiguous way to refer to me.
$ echo <(echo hi)
/dev/fd/63
If a program reads from that file path, it gets the output of the command chain. $ cat <( (echo foo; echo bar) | grep bar )
bar
Of course, that's a silly example. But that explains how the diff example works, since it's the same idea: diff just reads from the two "files".EDIT: Heh, 5 different replies within the same 60 second window.
<()
See? Penguin!