How do I get the path of a process in Linux
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.
You can find the exe easily by these ways:
ll /proc/<PID>/exe
pwdx <PID>
lsof -p <PID> | grep cwd
ps -ef | grep 786
pwdx <PID>
gave me the location of the symbolic link so I could find the logs and stop the process in proper way
pwdx <process id>
This command will fetch the process path from where it is executing.
The below command search for the name of the process in the running process list,and redirect the pid to pwdx command to find the location of the process.
ps -ef | grep "abc" |grep -v grep| awk '{print $2}' | xargs pwdx
Alternatively, if you could configure it as a function in .bashrc, you may find in handy to use if you need this to be used frequently.
ps1() { ps -ef | grep "$1" |grep -v grep| awk '{print $2}' | xargs pwdx; }
[admin@myserver:/home2/Avro/AvroGen]$ ps1 nifi
18404: /home2/Avro/NIFI
Leave a Comment