How do I get the path of a process in Unix / Linux

lsalamon picture lsalamon · Mar 3, 2009 · Viewed 190.2k times · Source

In Windows environment there is an API to obtain the path which is running a process. Is there something similar in Unix / Linux?

Or is there some other way to do that in these environments?

Answer

jpalecek picture jpalecek · Mar 3, 2009

On Linux, the symlink /proc/<pid>/exe has the path of the executable. Use the command readlink -f /proc/<pid>/exe to get the value.

On AIX, this file does not exist. You could compare cksum <actual path to binary> and cksum /proc/<pid>/object/a.out.