Finding the other end of a Unix pipe

If you need to see the other end of the a pipe, you can use either a find for the inode, or lsof, also on the inode.

We see our process of interest is waiting on a read call from file descriptor 4…

[root@cmhlpdlkedat01 ~]# strace -f -p 20352
Process 20352 attached - interrupt to quit
read(4, ^C 
Process 20352 detached

…so we see it has the following inode…

[root@cmhlpdlkedat01 ~]# ls -lrt /proc/20352/fd | awk '$(NF - 2) == 4'
lr-x------ 1 postgres postgres 64 Jul  3 11:08 4 -> pipe:[2789099945]

…so we can either recursively search /proc for the same inode…

[root@cmhlpdlkedat01 ~]# (find /proc -type l | xargs ls -l | fgrep 'pipe:[2789099945]') 2>/dev/null
lr-x------ 1 postgres postgres 64 Jul  3 11:08 /proc/20352/fd/4 -> pipe:[2789099945]
lr-x------ 1 postgres postgres 64 Jul  3 11:11 /proc/20352/task/20352/fd/4 -> pipe:[2789099945]
l-wx------ 1 postgres postgres 64 Jul  3 11:08 /proc/20406/fd/1 -> pipe:[2789099945]
l-wx------ 1 postgres postgres 64 Jul  3 11:11 /proc/20406/task/19955/fd/1 -> pipe:[2789099945]
l-wx------ 1 postgres postgres 64 Jul  3 11:11 /proc/20406/task/20406/fd/1 -> pipe:[2789099945]

…or use lsof…

[root@cmhlpdlkedat01 ~]# lsof | grep 2789099945
setup.php 20352  postgres    4r     FIFO                0,8        0t0 2789099945 pipe
osm2pgsql 20406  postgres    1w     FIFO                0,8        0t0 2789099945 pipe
[root@cmhlpdlkedat01 ~]#

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.