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

查看:43
本文介绍了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 执行,其中 是同时运行的作业数.

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

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

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