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 communityYou 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.
Yes, put strace
before each command in the pipeline and redirect the stderr to a different file for convenient analysis:
strace -o trace1.out command1 | strace -o trace2.out command2