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!


Leo 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.

poisonbit said...

Also can be written as:

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

Thanks for sharing :)

lindi said...


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

kovan said...

I usually use:

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

rgh said...

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