fourth fourth - 8 months ago 80
Bash Question

Why strace -f can't trace the child progress after |?

I am trying to see what would happen about system call when I running one command, but it seems those command after | can't be shown? like:

strace -f cat a.txt| cat

It seems strace and -f perimeter can show the whole process. I think the last part is in the child progress created by fork. Why and how to make it?


From the strace manual (emphasis mine).

-f Trace child processes as they are created by currently traced processes as a result of the fork(2), vfork(2) and clone(2) system calls.

The traced process in your case is the first cat process. The second cat process is not a child of the first cat process. The fork is done by the shell.

One way to achieve what you want is to trace the shell:

strace -f bash -c "cat a.txt| cat"