这里我想检查两个正在运行的进程之间的管道的状态。我可以使用ls -l在/proc/pid/fd中识别两端的管道文件描述符,从而识别管道编号,如下所示:
l-wx------ 1 user user 64 Jul 22 08:53 5 -> 'pipe:[135687452]'据我所知,管道在Linux vfs哲学中被视为一个文件,我怀疑有一些方法可以深入研究它,而不会干扰所有者进程。是否可以使用文件描述符或管道ID来访问更多的管道?我希望我能得到管道中的内容或管道中的内容长度。
非常感谢!
发布于 2021-07-25 12:31:13
阅读实际内容会扰乱所有者的进程。不过,您可以使用FIONREAD查看内容长度。每个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.https://stackoverflow.com/questions/68515136
复制相似问题