Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Am trying to trace apache2. These are the commands i'm trying to run.

ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace >> trace.txt

I tried

(ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace ) >> trace.txt

or

ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace | xargs >> trace.txt
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Any particular reason why you can't use the -o flag?

ps auxw | grep sbin/apache | awk '{print " -p " $2}' | xargs strace -o /tmp/trace.txt

Also, you should use some regex trick to not catch your grep process in the process list.

ps auxw | grep 'sbin/[a]pache' ....

Also remember that in the specific case of apache,

  1. Apache is (usually) multiprocess, do you want to get the parent or one of the children? I'd add the '-f' flag to strace, which (among other things) inserts the PID in the output.
  2. You can get the process ID of the main parent process from the PID file.

    e.g. strace -o /tmp//trace.txt -f $(< /path/to/apache.pid)

So, that's the question you're asking.. but what are you trying to do? Debug on startup? strace a child process serving a request? Also look at the -X flag to apache.

share|improve this answer
    
Hi Rich thanks for your answer. What i'm trying to do is see if there's a hiccup in the CPU usage. However '-c' option is not that useful for some reason. I also checked the trace.txt for timestamp for any weird increment and i don't see any. –  Marin Mar 6 '13 at 18:00
add comment
 ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace 2>> trace.txt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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