Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Interesting. What exactly have you done for your Master's project? Contributing code to the linux kernel or was it some literature work (such as making a presentation about the code)?

Can you elaborate on how to identify the filename for a pipe in procfs or sysfs in a simple "echo hello | wc -c" example?



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


Great response - Thank you. Seems I misunderstood the question.


If I remember correctly, this work was an end of semester advanced OS/Networking class presentation. I picked Pipes, others picked the filesystem, device drivers, CUDA, process scheduling etc. For the master’s thesis, my work was on active indoor localization and tracking (early work before indoor Google maps was launched).

Re: your second question, I guess you’re referring to identifying a FIFO on the filesystem - that’s a simple ls -la - FIFOs show up as regular files with the p attribute. For procfs or sysfs - just ls /proc or ls /sys

Man page: http://nersp.nerdc.ufl.edu/~dicke3/nerspcs/ls.html

You should see the p attribute for FIFOs on the filesystem. Sysfs and procfs map onto internal (in-memory) kernel data structures, so those might just show up as regular files in the “virtual” filesystem. So cat, grep etc. on these files will be just reads/writes from/to the appropriate memory space in the kernel or for read only files, they may be “code generated output” that allows for inspection of some internal state in the kernel.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: