161

If I have multiple copies of the same application on the disk, and only one is running, as I can see with ps, how can I know the absolute path to distinguish it from the others?

Jader Dias
  • 16,236

8 Answers8

188
% sudo ls -l /proc/PID/exe

eg:

% ps -auxwe | grep 24466
root     24466  0.0  0.0   1476   280 ?        S     2009   0:00 supervise sshd
% sudo ls -l /proc/24466/exe
lrwxrwxrwx 1 root root 0 Feb  1 18:05 /proc/24466/exe -> /package/admin/daemontools-0.76/command/supervise
Breakthrough
  • 34,847
akira
  • 63,447
40

Use:

pwdx $pid

This gives you the current working directory of the pid, not its absolute path.

Usually the which command will tell you which is being invoked from the shell:

#> which vlc
/usr/bin/vlc
seenu
  • 451
20

One way is ps -ef

fpmurphy
  • 1,661
7
ps auxwwwe

Source:

https://serverfault.com/questions/62322/getting-full-path-of-executables-in-ps-auxwww-output

Jader Dias
  • 16,236
7

lsof is an option. You can try something like below:

lsof -p PROCESS_ID

This will list all the files opened by the process including the executable's actual location. It is then possible to add a few more awk, cut, grep etc. to find out the information that you are looking for.

As an example, I executed the following commands to identify where my 'java' process came from:

lsof -p 12345 | awk '{print $NF}' | grep 'java$'
Pablo A
  • 1,733
ram
  • 71
2

The quick answer is to use ps with options or the /proc filesystem info. That will usually work, but is not guaranteed. In general, there is no definite, guaranteed answer. For instance, what if the executing file is deleted during execution, so that there is no path to the file?

See the Unix FAQ for a little more detail, particularly questions 4.3 and 4.4.

mpez0
  • 2,842
0

You could use

readlink /proc/$(pgrep -x -U $(id -ur) APP_NAME)/exe

or

find /proc/$(pgrep -x -U $(id -ur) APP_NAME)/exe -printf "%l\n"

to get the absolute path of APP_NAME running as current user.

jarno
  • 400
0

UPDATED due to David Moles' comment, below.

See other answers for the path to the executable.

In case you need it, this will give you the working directory of the process. You don't need to know the PID:

pwdx `pgrep ###process_name###`
moodboom
  • 745