Home » Questions » Computers [ Ask a new question ]

How can I know the absolute path of a running process?

How can I know the absolute path of a running process?

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?

Asked by: Guest | Views: 306
Total answers/comments: 5
Guest [Entry]

"% 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"
Guest [Entry]

One way is ps -ef
Guest [Entry]

"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."
Guest [Entry]

"Why does everyone expect you to know the PID? Here's the human-friendly way:

pwdx `pgrep ###process_name###`"
Guest [Entry]

"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."