Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace | xargs >> trace.txt
share|improve this question
up vote 4 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/

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
 ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace 2>> trace.txt
share|improve this answer

You can also direct standard out to a file this way:

(time /bin/ls) &> /tmp/time.txt

or for debugging a php script:

(strace php /path/to/www/script.php) &> strace_output.txt
share|improve this answer

You must log in to answer this question.

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