繁体   English   中英

如何在C ++中并行执行系统命令

[英]How to execute system command in parallel in c++

通常,当我想从C ++代码运行可执行文件时。 我只是使用代码:

system("path\to\the\executable param"); 

现在,我想并行运行可执行文件。 我使用2个线程。 第一个线程将调用:

system("path\to\the\executable param1");

第二个线程将调用:

system("path\to\the\executable param2");

但是,它并没有按照我的预期并行运行。

有办法解决这个问题吗?

您可以运行以下多个命令:

system("path\\to\\the\\executable param1 &");
system("path\\to\\the\\executable param2");

这样,两者将并行运行,并且您的程序不需要为此是多线程的。

  • 对于Windows:CreateProcess(请参阅MSDN)功能。
  • 对于* NIX:首先,用fork分支一个子代,然后用execXX (execl, execle ,execlp,execv,execvp)替换一个子代代码。

暂无
暂无

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

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