简体   繁体   English

嵌入式C:不同的进程向同一输入/输出发送/接收数据

[英]Embedded C: Different processes sending/receiving data to same input/output

So here is what I'm trying to accomplish it: 因此,这就是我想要实现的目标:

处理通讯图

  1. Telnet Client sends a command to Telnet Server (Process 1); Telnet客户端向Telnet服务器发送命令(过程1); - DONE -完成

  2. Process 1 finds which following Process (2, 3, 4 etc) will execute that command and calls that process - DONE 进程1查找以下哪个进程(2、3、4等)将执行该命令并调用该进程-完成

  3. The Telnet Client now needs to see the output of those other processes (say, Process 2) that is executing the command. Telnet客户端现在需要查看其他正在执行命令的进程(例如,进程2)的输出。 Process 2 might also need some extra input from the Telnet Client. 进程2可能还需要Telnet客户端的一些额外输入。 These are the outer arrows in red. 这些是红色的外部箭头。

  4. Process 2 will tell Process 1 once it is done. 流程2完成后将通知流程1。

My biggest (and maybe only) question is about step 3. How can that be achieved in an efficient way? 我最大(也许唯一)的问题是关于步骤3的。如何有效地做到这一点? Is it just a matter of piping stdin of Process 1 to stdin of Process 2, and then stdout of Process 2 to stdout of Process 1? 仅仅是将流程1的stdin传递到流程2的stdin,然后将流程2的stdout传递给流程1的stdout的问题?

Not that this question has anything to do with embedded, but the "proper" way to do it would be to have the telnet server act as an intermediary for all communication between the client and the subprocesses 2...n. 并不是说这个问题与嵌入式程序有关,而是“正确”的方法是让telnet服务器充当客户端与子进程2 ... n之间所有通信的中介。

I'd be highly suspicious of claims that making a pipe between the client and process 2...n to handle the communication from the client to the subprocess would be more "efficient", unless you're measuring efficiency in latency (ie you're working on something where the shortest time possible is desired...like high frequency stock trading). 我非常怀疑这样的说法,即在客户端和流程2 ... n之间建立一条管道来处理从客户端到子流程的通信会更“有效”,除非您要测量延迟效率(即正在从事可能需要最短时间的工作(例如高频股票交易)。

And it's a bit more than just piping stdin/stdout. 它不只是传递stdin / stdout。 The server needs to mirror the stdin/out (and probably stderr) to the telnet's socket programmatically. 服务器需要以编程方式将stdin / out(可能还有stderr)镜像到telnet的套接字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM