从 makefile 并行运行两个进程

发布于 2025-01-04 00:20:20 字数 224 浏览 1 评论 0原文

我正在尝试运行服务器和客户端以从 makefile:

target:

   ./server&
   ./client

运行,问题是 server&即使我认为它应该在后台运行,也永远不会返回控制权。它不断监听从未被调用的客户端,因为 makefile 似乎没有从服务器拿回控制权。我该如何解决这个问题?无需编写任何额外的目标或脚本?

I am trying to run both a server and client to run from a makefile:

target:

   ./server&
   ./client

The problem is that server& never returns the control back even though I assume it should run in the background. It keeps listening for client which is never invoked as the makefile does not seem to get the control back from server. How can I solve this issue?. without writing any additional target or scripts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百善笑为先 2025-01-11 00:20:20

您应该能够通过将命令组合在一行上来完成此操作:

target:
     ./server& ./client

将命令行设置为 shell ($(SHELL)) 一次一行

或者,您可以定义两个独立的目标:

target: run_server run_client

run_server:
     ./server
run_client:
     ./client

并使用 -j 选项运行 make 以使其并行化构建步骤:

make -j2

这似乎不是启动程序(例如用于测试)的最自然的解决方案,但可以使用当您有大量可以部分并行构建的构建规则时最好。 (有关 make-s 目标并行化的更多控制,另请参阅

.NOTPARALLEL

<块引用>

如果将 .NOTPARALLEL 指定为目标,则即使给出了 '-j' 选项,make 的调用也将串行运行。任何递归调用的 make 命令仍将并行运行配方(除非其 makefile 也包含此目标)。此目标的任何先决条件都将被忽略。

You should be able to do this by combining the commands on a single line:

target:
     ./server& ./client

Make hands commandlines to the shell ($(SHELL)) one line at a time.

Alternatively, you could define two independent targets:

target: run_server run_client

run_server:
     ./server
run_client:
     ./client

and run make with the -j option to make it parallelize build steps:

make -j2

This would not appear the most natural solution for launching your program (e.g. for test) but works best when you have large numbers of build rules that can be partly built in parallel. (For a little more control on make-s parallellization of targets, see also

.NOTPARALLEL

If .NOTPARALLEL is mentioned as a target, then this invocation of make will be run serially, even if the ‘-j’ option is given. Any recursively invoked make command will still run recipes in parallel (unless its makefile also contains this target). Any prerequisites on this target are ignored.

記柔刀 2025-01-11 00:20:20

server 在后台运行。您可以使用命令fg将其置于前台。然后用 Ctrl-C 杀死它

或者用这个方法: killall server

server runs in background. You may put in foreground using command fg. And then kill it with Ctrl-C

Or maybe this method: killall server

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文