Makefile在后台运行进程 [英] Makefile run processes in background

查看:507
本文介绍了Makefile在后台运行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Makefile中有这个文件:

I have this in my Makefile:

run:
     for x in *.bin ; do ./$$x ; done

使其一一启动所有可执行文件.我想这样做:

such that it launches all executables one by one. I want to do this:

run:
     for x in *.bin ; do ./$$x &; done

,以便启动每个可执行文件并将其放在后台.放置&"号时,出现上述语句的语法错误.

so that it starts each executable and puts it in the background. I get a syntax error for the above statement when I put the ampersand.

我不想以make &调用make,因为这将在后台运行进程,但仍然是一个接一个地运行,而我希望单个可执行文件在后台运行,因此在任何时候我都可以拥有多个可执行文件跑步.

I dont want to invoke the make as make & since this will run processes in the background but still one by one, whereas I want individual executables to run in the background, so that at any instant I have more than one executable running.

谢谢.

推荐答案

尝试通过子shell执行:

Try to execute via a subshell:

run:
     for x in *.bin ; do (./$$x &); done

也许make -j是更好的选择.尝试如下所示的Makefile:

Maybe make -j is a better option. Try a Makefile that looks something like this:

BINS = $(shell echo *.bin)

.PHONY: $(BINS)
run: $(BINS)

*.bin:
    ./$@

然后使用make -j <jobs>执行,其中<jobs>是要运行的同时作业数.

And then execute with make -j <jobs> where <jobs> is number of simultaneous jobs to run.

这篇关于Makefile在后台运行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆