>echo > foobar.c
>strace gcc -c foobar.c 2>&1 | grep foobar.o
>
(无) -foobar.o
显然是写入的,但我在 strace 上没有看到它。为什么?
答案1
这是因为gcc
创建子进程,并且strace
除非您指定标志,否则不会查看子进程-ff
。
查看strace -ff
本例中标志的实际作用:
deltik@workstation [~/Desktop]# echo > foobar.c
deltik@workstation [~/Desktop]# strace -ff gcc -c foobar.c 2>&1 | grep foobar.o
[pid 14220] execve("/usr/local/sbin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */]) = -1 ENOENT (No such file or directory)
[pid 14220] execve("/usr/local/bin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */]) = -1 ENOENT (No such file or directory)
[pid 14220] execve("/usr/sbin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */]) = -1 ENOENT (No such file or directory)
[pid 14220] execve("/usr/bin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */] <unfinished ...>
[pid 14220] stat("foobar.o", 0x7ffed65b3850) = -1 ENOENT (No such file or directory)
[pid 14220] open("foobar.o", O_RDWR|O_CREAT|O_TRUNC, 0666) = 3