If I know the PID number of a process, how can I get its name?
If I have the PID number for a process (on a UNIX machine), how can I find out the name of its associated process?
What do I have to do?
On all POSIX-compliant systems, and with Linux, you can use ps
:
ps -p 1337 -o comm=
Here, the process is selected by its PID with -p
. The -o
option specifies the output format, comm
meaning the command name.
For the full command, not just the name of the program, use:
ps -p 1337 -o command
See also: ps
– The Open Group Base Specifications Issue 6
You can find the process name or the command used by the process-id or pid from
/proc/<pid>/cmdline
by doing
cat /proc/<pid>/cmdline
Here pid is the pid for which you want to find the name
For example:
# ps aux
................
................
user 2480 0.0 1.2 119100 12728 pts/0 Sl 22:42 0:01 gnome-terminal
................
................
To find the process name used by pid 2480 you use can
# cat /proc/2480/cmdline
gnome-terminal
To get the path of of the program using a certain pid you can use:
ps ax|egrep "^ [PID]"
alternatively you can use:
ps -a [PID]
Or also:
readlink /proc/[PID]/exe