fourth fourth - 1 year ago 115
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?

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download