|
> Can you elaborate on how to identify the filename for a pipe in procfs or sysfs in a simple "echo hello | wc -c" example? You can see it under /proc/$pid/fd. For example, if you run "sleep 600|wc -c" (just to give yourself some time to poke around), you can see: $ ls -l /proc/2760791/fd
total 0
lrwx------ 1 ams ams 64 Mar 28 13:35 0 -> /dev/pts/10
l-wx------ 1 ams ams 64 Mar 28 13:35 1 -> pipe:[54074122]
lrwx------ 1 ams ams 64 Mar 28 13:35 2 -> /dev/pts/10
$ ls -l /proc/2760792/fd
total 0
lr-x------ 1 ams ams 64 Mar 28 13:35 0 -> pipe:[54074122]
lrwx------ 1 ams ams 64 Mar 28 13:35 1 -> /dev/pts/10
lrwx------ 1 ams ams 64 Mar 28 13:35 2 -> /dev/pts/10
Here 2760791 is the pid of the "sleep 600", and 2760792 is the pid of "wc". You can see they're both connected to "pipe:[54074122]".54074122 is the (virtual, i.e., not disk-based) inode of the pipe. You can get substantially the same information from lsof: $ lsof -E -u ams|egrep 'sleep|wc'|grep pipe
sleep 2760791 ams 1w FIFO 0,13 0t0 54074122 pipe 2760792,wc,0r
wc 2760792 ams 0r FIFO 0,13 0t0 54074122 pipe 2760791,sleep,1w
But the name "pipe:[54074122]" is actually the "filename" of the pipe, and it comes from here in fs/pipe.c: static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen)
{
return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]",
d_inode(dentry)->i_ino);
}
(There's an interesting note in Documentation/filesystems/vfs.txt about how pseudo-filesystems like pipefs can generate these names only when someone asks for them, since they're not used for anything otherwise. The only way I know of to ask for the name in this case is to call readlink() on the pipe fd under /proc/$pid/fd, as ls does.) |