对于 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/