2

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.

1
  • 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, 2011 at 14:30

2 Answers 2

1

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.

1

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.

1
  • 2
    I also just found out by accident, that pressing c while viewing "top" output gives the full command names. Neat :)
    – Kipras
    Jul 29, 2011 at 9:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .