1

I have a pipeline like this:

command1 | command2

Is there a way to trace both commands simultaneously?

4

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.