how to find out all the PID of Apache httpd processes that are in reading state?

21,763

Solution 1

Try using netstat program with the -l flag to get a list of listening process. You probably want to run it with sudo so that you can use the -p flag to get process PIDs. You might also want the -t flag to only show tcp sockets instead of tcp and udp. Sometimes the -n flag is nice to show only port numbers and IPs without resolving them to services and names.

After that it's a matter of greping for just your apache process and then extracting the PID from the output columns:

sudo netstat -lntp | grep httpd | awk -F '[/ ]*' '{print $7}'

Solution 2

To find out the details about connections which are spending more than 15 seconds in HTTP request reading phase, I wrote this command:

links http://localhost/server-status | tee | grep "..reading.." | awk '{if ($6>15) print "lsof -a -n -i TCP -p"$2}' | sh |  grep -E "TCP.*(ESTABLISHED)"
Share:
21,763

Related videos on Youtube

Sabya
Author by

Sabya

Updated on September 18, 2022

Comments

  • Sabya
    Sabya over 1 year

    The Apache web server in my RHEL shows many requests in R (..reading..) state. I want to find the client IPs that are making Apache wait in reading state. Specifically: I want to find out all the client IPs that are spending too long to send the request.

    The server-status module is not enough. Server status does not show the client information when the PID is in reading state.

  • Yzmir Ramirez
    Yzmir Ramirez over 7 years
    What does links do? What distro are you using where that's available?
  • allanlaal
    allanlaal about 7 years
    its a command line web browser
  • MrG
    MrG over 6 years
    This requires Apache module mod_status to be enabled as described here: serverfault.com/questions/350559/…