I had a problem recently, where a perl script was consuming server resources. I found out it was a perl script by using "top". But it didn't give the path to the script. Nor did ps. Also, ps -ef showed that the process with that pid is /usr/bin/httpd (apache), so it must have been apache serving some perl page I suppose.

Is it possible to get the path to currently running perl script, if I only know the process PID of the perl process that is running that script? If so, how?

Clarification: I don't need the path to the perl binary, I need the path to the perl script that binary is currently executing.

link|improve this question
ps aux should tell you when the perl process was started, combine with Apache access logs to find the responsible script. – Daniel Beck May 1 '11 at 14:30
feedback

2 Answers

up vote 1 down vote accepted

You can do ps -p $p -o command , where instead of $p you use the PID of the process. This gives the full command line.

link|improve this answer
feedback

Take a look in /proc for the PID of the process. In there is a file cmdline

That contains the command that was used to run the script.

eg:

$ cat /proc/19433/cmdline
perl/path/to/myscript

There is actually \000 (chr(0) / NULL) between the "perl" and the "/path..." but cat doesn't show it.

link|improve this answer
I also just found out by accident, that pressing c while viewing "top" output gives the full command names. Neat :) – Kipras Jul 29 '11 at 9:22
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.