## Hardware and performance

### Question re using linux TOP and associating PID with process/task

This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
Question re using linux TOP and associating PID with process/task

Hi there!

Moodle version 2.4.5
Apache

Hoping there are some linux geeks out there that might be able to help answer my question smile  I know my way around linux systems but am by far an expert.

I'm using the TOP command to view cpu and mem usage on our Moodle server.  I know the basics and I'm slowly learning how to interpret the data so it is actually useful.

I switched my display so I could see the actual path vs. just the command and this was very useful.

My question is: is there a way to find out, or associate, an actual PID with an httpd task?

For example, I recently encountered a corrupted gradebook.  When I, as admin, clicked on this gradebook on the website the website became unresponsive and the cpu spiked to about 95%.  Because I was running TOP at the time it was pretty obvious what the PID was and I could kill it however, if I wanted to find out what was actually causing a cpu or mem spice caused by a particular process, how would I go about doing that?  Some things are obvious, for example, if cron is running it will clearly show that in the command line, but if the command shows /usr/sbin/httpd this indicates a connection/or session, no?

NOTE: I fixed the corruption issue, I just wanted to use that as an example, I really just want to know how to associate a PID with an actual event happening on moodle.

Thanks!!!!!

ps... apologies for the cross post in the General forum, I realize this topic would be better handled in this forum?

Average of ratings: -
Re: Question re using linux TOP and associating PID with process/task
Hi Susan

You wrote:
> ps... apologies ...

No need to apologize, that was the answer: ps as in 'process status'!

For example
$ps -p PID -o pcpu (replace PID with the PID of the process you are interested in) or to see the most interesting processes:$ ps -eo pcpu,pid | sort -r | head

see 'man ps'.

Average of ratings: -
Re: Question re using linux TOP and associating PID with process/task

ha ha!  Thanks!

Actually I already tried using ps but didn't get quite what I was looking for.  I want to link up a PID with an actual task, or user or course for example.  I understand that this will require more work than just viewing through TOP but I'm not sure where to start. Not sure if this is possible ....?

Average of ratings: -
Re: Question re using linux TOP and associating PID with process/task
So your question is, once a user submits the assignment X in course Y, for example, you want to know the PID of the corresponding process? That is an impossible premise because a) it may spawn more than one process b) PHP shields them. The closest you can go is to log the performance information Moodle generates in its footer, once "Performance info" is activated. But beware, that'll have a negative effect on performance!

Average of ratings: -
Re: Question re using linux TOP and associating PID with process/task

Apache's mod_status will give you a list of active requests along with the PIDs of the processes handling the requests.  With this you could take a PID you see in top and map it to a request like 'GET /login/index.php'.  Take a look at https://httpd.apache.org/docs/2.2/mod/mod_status.html for more information on mod_status.

Keep in mind that most of the time an Apache process will handle many requests in its lifetime, so by the time you look at the output of mod_status, the process who's PID you have could already be handling another request.  But since you only sound interested in figuring out what long running CPU intensive processes are doing, chances are that the process in question will still be doing the same thing when you look at mod_status.

If you want to get into the real nitty gritty of what a process is doing you could use strace -p <pid> and see all the system calls that the process is making.  You'll probably find the output pretty cryptic if you are new to Linux, but it could be fun to take a look.

Average of ratings: Useful (2)
Re: Question re using linux TOP and associating PID with process/task

Thank-you!

Average of ratings: -