如何获得管道另一侧的pid?

我想知道管道另一侧的pid。如果是Linux,我可以像这些命令一样匹配
ls -l /proc/SELF_PID/fd/0
的id。 [root @ host~]#command1 | command2& 我知道command2的PID = 5912。 [root @ host~] #ls -l / proc / 5912 / fd / 0 lr-x ------ 1 root root 64 Mar 25 18:00 / proc / 5912 / fd / 0 - > pipe:[540748072] [root @ host~] #ls -l / proc / [0-9] * / fd / 1 | grep'pipe: [540748072 ]' l-wx ------ 1 root root 64 Mar 25 18:01 / proc / 5911 / fd / 1 - > pipe:[540748072] [root @ host~] #cat / proc / 5911 / cmdline vmstat12 Linux上有更好的方法吗?或者如何使用BSD和其他操作系统? 我想知道是否有一个好的CPAN模块...... 谢谢。     
已邀请:
在Perl中,进程可以使用特殊变量$$获取自己的PID 如果你有一对管道或一个套接字,每个进程只需将自己的PID发送到管道或套接字即可由另一个进程读取。 此外,父母通常通过系统调用来了解他们孩子的PID。     

要回复问题请先登录注册