Is it possible to write a program that's able to take another application's open file descriptors and just pass along their contents without any conversion?
是否有可能编写一个程序,使它能够接受另一个应用程序的打开文件描述符,并在不进行任何转换的情况下传递它们的内容?
Let's say App A has an open FD to some file on disk that it's writing data to.
假设App A有一个打开的FD到它写入数据的磁盘上的某个文件。
I'd like to be able to somehow get access to the open FD so that anytime App A writes data to that file I can broadcast that write to some other App that's interested in that operation.
我希望能够以某种方式访问开放的FD以便应用A将数据写入文件时,我可以将其写入到其他对该操作感兴趣的应用。
I'd like to be able to multiplex the read/write operations on open FD.
我希望能够对open FD上的读/写操作进行多路复用。
A more concrete example; I have a midi keyboard and some synthesizers, i'd like to be able to open the midi keyboard file descriptor and pass all the incoming write operations to 0-N interested synthesizers.
一个更具体的例子;我有一个midi键盘和一些合成器,我希望能够打开midi键盘文件描述符并将所有传入的写操作传递给0-N感兴趣的合成器。
1 个解决方案
#1
1
strace
has an option that does the main part of what you want.
strace有一个选项,可以完成你想要的主要部分。
-e write=set Perform a full hexadecimal and ASCII dump of all the data written to file descriptors listed in the spec- ified set. For example, to see all output activity on file descriptors 3 and 5 use -e write=3,5. Note that this is independent from the normal tracing of the write(2) system call which is controlled by the option -e trace=write.
- if your app A is already running:
strace -ewrite -ewrite=FD -pPID
- 如果你的app A已经运行了:strace -ewrite -ewrite=FD -pPID。
- if your app A is yet to be started:
strace -ewrite -ewrite=FD A
- 如果你的应用A还没有启动:strace -ewrite -ewrite=FD A
It is trivial to convert the produced hexadecimal dump back to raw data and feed that to other apps.
将生成的十六进制转储转换回原始数据并将其提供给其他应用程序是非常简单的。
#1
1
strace
has an option that does the main part of what you want.
strace有一个选项,可以完成你想要的主要部分。
-e write=set Perform a full hexadecimal and ASCII dump of all the data written to file descriptors listed in the spec- ified set. For example, to see all output activity on file descriptors 3 and 5 use -e write=3,5. Note that this is independent from the normal tracing of the write(2) system call which is controlled by the option -e trace=write.
- if your app A is already running:
strace -ewrite -ewrite=FD -pPID
- 如果你的app A已经运行了:strace -ewrite -ewrite=FD -pPID。
- if your app A is yet to be started:
strace -ewrite -ewrite=FD A
- 如果你的应用A还没有启动:strace -ewrite -ewrite=FD A
It is trivial to convert the produced hexadecimal dump back to raw data and feed that to other apps.
将生成的十六进制转储转换回原始数据并将其提供给其他应用程序是非常简单的。