Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list pipes used by a process with a bash command

Is there a way to list pipes used by a running linux process (e.g. given its pid or process name) and to determine their used capacity?

Something like:

lspipes -l -p pid

resulting in something like:

[rw]  descriptor  size  name

where rw is the pipe end type and size is its used capacity

Or something similar

like image 617
a1an Avatar asked Sep 05 '12 14:09

a1an


People also ask

What is the pipe command in bash?

A pipe in Bash takes the standard output of one process and passes it as standard input into another process. Bash scripts support positional arguments that can be passed in at the command line.

What are pipes in command line?

The | command is called a pipe. It is used to pipe, or transfer, the standard output from the command on its left into the standard input of the command on its right. # First, echo "Hello World" will send Hello World to the standard output.

What is the pipe command in Linux?

Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command's output may act as input to the next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes.

How do you grep a pipe?

To use grep as a filter, you must pipe the output of the command through grep . The symbol for pipe is " | ".


2 Answers

1) ls -l /proc/pid/fd

This will list the pipes

lr-x------ 1 prabagaran prabagaran 64 Sep  5 23:01 14 -> pipe:[57729]
l-wx------ 1 prabagaran prabagaran 64 Sep  5 23:01 15 -> pipe:[57728]
lr-x------ 1 prabagaran prabagaran 64 Sep  5 23:01 16 -> pipe:[57731]
lr-x------ 1 prabagaran prabagaran 64 Sep  5 23:01 17 -> pipe:[57730]

2) lsof | grep 57731

wineserve 3641 prabagaran   76w     FIFO        0,8       0t0   57731 pipe
winedevic 3651 prabagaran   16r     FIFO        0,8       0t0   57731 pipe

These are the pipe information related to the given process id.

like image 158
Prabagaran Avatar answered Sep 28 '22 12:09

Prabagaran


I don't really think there's such a command. You can try the following:

lsof -p <PID> | grep "FIFO"

Where <PID> stand for the process id. Probably there's a lsof switch to select only pipes and avoiding the grep, but I cannot find it in the man page right now.

It should give you something close to what you're looking for.

like image 28
Zagorax Avatar answered Sep 28 '22 11:09

Zagorax