【问题标题】:Can I do something with a pipe of other process?我可以用其他进程的管道做些什么吗?
【发布时间】:2021-07-25 02:40:23
【问题描述】:

在这里,我想检查两个正在运行的进程之间的管道状态。我可以在/proc/pid/fd 中识别两端的管道文件描述符,因此使用ls -l 的管道号如下:

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

我知道管道在 Linux vfs 哲学中被视为一个文件,我怀疑有一些方法可以在不干扰所有者进程的情况下深入研究它。我可以用文件描述符或管道 ID 做些什么来访问更多的管道吗?希望能得到管道中的内容或者管道中的内容长度。

非常感谢!

【问题讨论】:

    标签: linux pipe


    【解决方案1】:

    阅读实际内容会干扰所有者进程。不过,您可以使用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.
    

    【讨论】:

      猜你喜欢
      • 2020-07-31
      • 1970-01-01
      • 2012-10-11
      • 2014-03-22
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      相关资源
      最近更新 更多