Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Right now I'm dealing with a client's php based site that is somehow clogging up all of the available processes he has with his shared hosting provider. I'd like to prove to him exactly what and how many processes are being ran at a time when a specific index page is being loaded in a browser. I can see about 5 or 6 pop off at a time in top, but they all go away and come back so quickly I can't get a bead on any specific pid to trace.

Anyone have an idea of how I can anticipate the pid number I should be following to find out what his site specifically is doing?

share|improve this question

2 Answers 2

Use ps or pstree to find the parent pid for whatever you want to trace, I'm assuming it's probably apache? Then, use the -f option to strace so it follows all child pids too. Finally if you have a relatively recent strace you can just trace the process activity with -e trace=process.

Putting it all together, and assuming your apache parent process is pid 1234:

strace -o logfile.txt -f -e trace=process -p1234

should get you pretty close to where you want to go.

share|improve this answer
    
That would work, but I need to figure out what pid I should be following. Shared Servers tend to have a bunch of open apache processes, I'm trying to figure out which one of those it's going to use so I can strace... –  b1ackjosh Nov 8 '11 at 7:55
    
I wonder if you can find the apache pid in a lockfile or logfile? –  Phil Hollenback Nov 16 '11 at 17:29

I wonder if the following concept would be too slow (even if scripted) to catch the pid:

  1. Make inotifywait wait for specific index page access.
  2. Configure inotifywait to trigger

strace -o /tmp/wtf -f -e trace=process -p $(lsof -t /path/to/specific/index.php)

Or something similar. This was just a wild guess without actually trying above.

See also: XDebug and KCacheGrind.

share|improve this answer
    
+1 for the XDebug mention. Trying to debug PHP with strace is going to be pretty painful. –  Zoredache Nov 8 '11 at 8:32
    
Doesn't look like this server is configured with inotifywait, good idea though. the lsof trick is nice as well I'll have to give that a try. Edit: ah dang it, the lsof trick isn't working either. :( Edit2: actually that's my bad lsof trick does work thanks Janne :D –  b1ackjosh Nov 8 '11 at 9:48

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.