2

I have a pipeline like this:

command1 | command2

Is there a way to trace both commands simultaneously?

2 Answers 2

9

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .