简体   繁体   English

同时运行两个程序C / C ++

[英]Run two programs at the same time C/C++

I was reading this article about Inter-Process communication with message passing. 我正在读文章关于与消息传递的进程间通信。 In order to run the examples and see the it says and I quote: "should be compiled and run at the same time". 为了运行示例并查看其内容,我引用:“应同时编译并运行”。 Someone has any ideas how exactly should I do this? 有人有任何想法我应该怎么做?

You can create BAT file and start both programs almost simultaneously: 您可以创建BAT文件并几乎同时启动两个程序:

START first.exe
START second.exe

"should be compiled and run at the same time" “应同时编译并运行”

I think it is clear a program can not be run until after it is compiled (this is a minor grammatical issue, and should be ignored). 我认为很明显,程序必须等到编译后才能运行(这是一个较小的语法问题,应该忽略)。


In Linux, my preferred mechanism to launch a process is popen invoked by my C++ program. 在Linux中,我首选的启动进程的机制是由我的C ++程序调用popen的。

In C++, it is easy for one thread (let us call this your start process) to use popen to launch as many processes as needed for your application (call these work processes). 在C ++中,一个线程(让我们将其称为启动过程)很容易使用popen来启动应用程序所需的尽可能多的进程(称为这些工作进程)。

I would then use messages to synchronize the start up (ie work processes should initialize themselves, then wait (at startup) for a go message from start process). 然后,我将使用消息来同步启动(即工作流程应自行初始化,然后(在启动时)等待启动过程中的执行消息)。 These start up messages work in the same way your application would use them. 这些启动消息的工作方式与您的应用程序使用它们的方式相同。 This ensures that the multiple work processes are running at the same time (but within the constraints of how many cores your system has available). 这样可以确保多个工作流程同时运行(但要在系统可用核心数量的限制内)。

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

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