Linux – Using strace effectively

linuxPHPstrace

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?

Best Answer

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.