I have a pipeline like this:
command1 | command2
Is there a way to trace both commands simultaneously?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You can get a single trace with:
strace -f sh -c 'command1 | command2'
The "-f" will "follow" fork calls into the child processes (so you'll also get any sub-commands invoked by command1 or command2, which may or may not be what you want.) Also, you'll get a trace of the
sh process too. If you want each processes output in a separate file, the "-ff" option will trace subprocesses and append the PID to the "-o" filename, as in:
strace -ff -o trace sh -c 'command1 | command2'
This should create separate
trace.<PID> files for each forked child.