How to get the path details from the proccess ID

processpssolaris

In order to see the path of the running process 25014 I do on Linux the following:

  ls -l /proc/25014/exe

Output:

 lrwxrwxrwx 1 root root 0 Mar  9 16:35 /proc/25014/exe -> /etc/syscconfig

In case we have Solaris OS. What the same concept on Solaris? In Solaris we not have the exe file.

Best Answer

I'M THE AUTHOR AND THIS ANSWER IS INCORRECT AND SHOULD BE DELETED (cannot delete as it is the accepted answer). As pointed out in comments below it will return the process' working directory, aka current directory. Unless the process itself has changed its working directory then it will be the directory from which the process was started, not the directory of the executable. Bottom line: this answer is incorrect in the context of the question.


Here's one way of doing it.

In Solaris you would use the pargs -ae <pid> command for this.

The line that says argv[0]: will tell you what executable is running. This is however not enough as you do not know the current directory of that process when it was started so if arg0 is not fully qualified then you don't have the full path to the running application. Fear not. Look further down in the output of the above command and within the output of the process' environment variables look for PWD. Combine the two and you have the full path to the executable.

Here's some sample output from a pargs -ae command:

8200:   ./sshd
argv[0]: ./sshd

envp[0]: LANG=C
envp[1]: LC_ALL=
envp[2]: LC_COLLATE=
envp[3]: LC_CTYPE=
envp[4]: LC_MESSAGES=
envp[5]: LC_MONETARY=
envp[6]: LC_NUMERIC=
envp[7]: LC_TIME=
envp[8]: PATH=/usr/sbin:/usr/bin
envp[9]: PWD=/usr/lib/ssh
envp[10]: SHLVL=2
envp[11]: SMF_FMRI=svc:/network/ssh:default
envp[12]: SMF_METHOD=start
envp[13]: SMF_RESTARTER=svc:/system/svc/restarter:default
envp[14]: SMF_ZONENAME=myhost1
envp[15]: TZ=localtime
envp[16]: A__z="*SHLVL