What is Apache doing?

Ever wish you knew what Apache was working on at any given moment, but kicking yourself because you forgot to enable a server-status directive? This snippet will help you diagnose timeouts and long-running scripts (for bad coders like myself):

[code lang=”bash”]for i in `ps -elf |grep http|awk ‘{print $4}’|sort|uniq`; do ls -la /proc/$i/cwd ; done|awk ‘{print $11}’|sort|uniq -c |sort -nr [/code]


  • Srinivas

    November 23, 2011


    Just wondering what output if we ran above command? it just print only present working directory of process. if it is Apache, if usually print “/” as PWD.


  • kale

    January 24, 2012

    Hi Srinivas, sorry for the late reply. When you run this command, it will output what each Apache child is currently serving. If Apache is idle and there are no requests, you will only see “/”; however, if there is traffic, you should see something like this:

    [root@www2 ~]# for i in `ps -elf |grep http|awk ‘{print $4}’|sort|uniq`; do ls -la /proc/$i/cwd ; done|awk ‘{print $11}’|sort|uniq -c |sort -nr
    44 /
    2 /var/service/log
    1 /var/www/html/images/thumb_402.png

    This command is useful for finding things such as long-running scripts.

Leave a Reply