LTW
LTW

Reputation: 31

Can I do something with a pipe of other process?

Here I want to inspect the status of a pipe between two running processes. I can identify the pipe file descriptor of both end in /proc/pid/fd, and thus the pipe number using ls -l like this:

l-wx------ 1 user user 64 Jul 22 08:53 5 -> 'pipe:[135687452]'

As I know the pipe is seen as a file in the Linux vfs philosophy, I suspect there is some way to dive into it without disturbing the owner process. Is there anything I can do with the file descriptor or the pipe ID to access more to the pipe? I hope I can get the content in the pipe or the content length in the pipe.

Many Thanks!

Upvotes: 0

Views: 328

Answers (1)

Reading the actual content would disturb the owner process. You can use FIONREAD to see the content length, though. Per man 7 pipe:

   The following ioctl(2) operation, which can be applied to a file
   descriptor that refers to either end of a pipe, places a count of
   the number of unread bytes in the pipe in the int buffer pointed
   to by the final argument of the call:

       ioctl(fd, FIONREAD, &nbytes);

   The FIONREAD operation is not specified in any standard, but is
   provided on many implementations.

Upvotes: 1

Related Questions