I am trying to get application name by typing a command but it seems like there is no command to get application name from process id.
We can only get process name from using process id in command.
The command is ps -p <process id> o comm=
, which return process name.
I want to get application name by using of process id so my query is that:
which command I can use to get application name using the process id in Linux?
-
which linux are you using ?– KiwyJun 12, 2018 at 12:17
2 Answers
You could use /proc
on recent Linux:
ls -l /proc/[PID]/exe
#or
readlink /proc/[PID]/exe
This file should be a link to the executable use by this PID.
-
This is working for me on CentOS. I prefer readlink since it outputs only the executable. Thanks. Jun 12, 2018 at 12:37
-
@KevinLemaire it's a matter of taste. It more exploitable I have to agree. You're welcome– KiwyJun 12, 2018 at 12:38
On a platform with a standard procfs
with procfs-2 support, you get the result via:
ls -l /proc/<pid>/path/a.out
The file a.out is a symlink to the absolute path of the binary.