How to find out from which folder a process is running?

Solution 1:

Try this:

ls -l /proc/<PID>/cwd

Solution 2:

Derived rom HUB's answer:

readlink /proc/<PID>/cwd

or even

readlink /proc/$(pgrep <program_name>)/cwd

Solution 3:

You can't tell where a process was invoked from, only where it currently is. Look at the cwd ("current working directory") link instead of exe.

Solution 4:

Duplicate of https://unix.stackexchange.com/questions/94357/find-out-current-working-directory-of-a-running-process ?

There are 3 methods that I'm aware of:

pwdx

$ pwdx PID

lsof

$ lsof -p PID | grep cwd

/proc

$ readlink -e /proc/PID/cwd

Solution 5:

I guess this command should work. It is a little workaround but it works at least on my machine.

for strlist in $(ps e PID);do if [ ${strlist:0:4} = "PWD=" ]; then echo ${strlist:4};fi;done