linux - make 命令如何调用其他子 shell 来执行配方

标签 linux makefile gnu-make

对于 target 中的每个配方,make 调用不同的子 shell 来执行配方。 所以,我尝试了这个命令 strace make all 2>&1 | grep fork , 但没有得到 fork 系统调用的任何匹配项。我哪里错了?

最佳答案

您看不到对 fork 的调用,因为实际的系统调用是 clone。如果您检查 strace 的输出,就会看到这一点。我喜欢将 strace 输出保存在一个文件中,然后再查看它:

strace -o trace make all

如果我有一个如下所示的 Makefile:

three: one two
    cat one two > three

one:
    date > one

two:
    date > two

然后在运行上面的 strace 命令后,我有:

$ grep clone trace
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f6a3570ce50) = 29836
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f6a3570ce50) = 29838
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f6a3570ce50) = 29840

来自 fork 手册页:

   C library/kernel differences
       Since version 2.3.3, rather than invoking the kernel's fork() system
       call, the glibc fork() wrapper that is provided as part of the NPTL
       threading implementation invokes clone(2) with flags that provide the
       same effect as the traditional system call.  (A call to fork() is
       equivalent to a call to clone(2) specifying flags as just SIGCHLD.)
       The glibc wrapper invokes any fork handlers that have been
       established using pthread_atfork(3).

关于linux - make 命令如何调用其他子 shell 来执行配方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41776601/

相关文章:

c++ - 以编程方式查询 Linux 机器的电源状态

java - gcc -x java on debian stretch

linux - 构建 Pulseaudio-11.1 和 intltool >= 0.35.0 错误

assembly - 修改Makefile生成程序集

makefile - GNU Make 支持文件名中的 '%' 吗?

makefile - 指定编号的 Make -j(多个作业)在 QNX 中不起作用

c - 为什么信号处理出现故障?

bash - 在 Makefile 中提取操作系统名称和版本号

macos - 如何运行 "gmake install"?

Python - 混淆了如何编写代码来读取文件以更新动态字典以进行查找