Is it possible to get a file name of a process using PID? ps displays a lot of useful information about a process, but not a hint about a process executable file location.
|
One way of getting the process's binary location is to use lsof and grep for the first txt segment. For example, in the shell to see what binary the shell is, use the shell's PID in $$
You can see that the shell is using /bin/bash. This technique works if the process was launched using an absolute or relative path. For example, going into one shell and running
and using ps in another shell only shows how it was launched:
using lsof shows which binary it ran:
I have MacPorts coreutils +with_default_names installed, which explains that I picked up gsleep and not /bin/sleep. |
||||
|
|
|
Example: you're after the associate process command name for
|
|||||
|
|
ps -ef with grep works for me. For a specific file name, simply pipe through grep thus:
(That final 'grep -v grep' simply stops you getting your own grep command in the output) |
|||
|
|
|
ps -p <pid> -Ocommand
|
|||
|
|