Posted 25 February 2010 - 05:21 PM
Every process has their own folder located in /proc. The directory name of the process is the same as the process's ID. In other words, let's say your script's process ID is 3, its process information would be located at /proc/3. However, Linux provides a directory known as "self." The self directory located at /proc/self is used to access the currently running program. This allows the program to obtain information about itself without having to know its process ID. I, however, do not know which file or directory you would have to read from in order to obtain the current CPU usage of the process, but this should provide some insight for you.
Using PHP functions, i only know how to have PHP tell me how much memory it wasted and how long it took to execute the script. You can probably find a system tool that can retrieve the CPU usage by process ID and use exec() to retrieve the information from stdout, but i don't know what program exactly that would be.