2010-11-05

"multi-strace"

Thanks to a colleague, we hereby present the multi-strace:
strace $(pgrep httpd | awk '{ print "-p " $1 }' | tr '\n' ' ')
(it's left as exercise to the reader to understand what it does) if you want to save the output and the play with it, just add '-o <file>'.

Welcome, new handy tool!

5 comments:

Leo Antunes said...

For completeness' sake, you could also use:
# pgrep httpd | sed 's/^/-p /' | xargs strace

Seems a bit easier to read, IMHO. Though naturally not so cool! :)

BTW, it seems xargs could use some sort of argument like "automatically prepend arguments with X". Would neatly make this sort of hack useless.

Anonymous said...

Also can be written as:

strace $(printf -- '-p %s ' $(pgrep httpd) )

Thanks for sharing :)

Anonymous said...

Or

strace -p$(pgrep -d\ -p httpd)

Anonymous said...

I usually use:

for i in $(ps -eLf |grep NAME |awk '{print $4}'); do (strace -p $i 2>&1 &); done

Anonymous said...

Leo, you mean like this:
pgrep httpd | xargs -i strace -p {}