Glam Prestige Journal

Bright entertainment trends with youth appeal.

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?

4

9 Answers

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

3

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
2

To get the path of of the program using a certain pid you can use:

ps ax|egrep "^ [PID]"

enter image description here

alternatively you can use:

ps -a [PID]

Or also:

readlink /proc/[PID]/exe
2

You can use pmap. I am searching for PID 6649. And cutting off the extra process details.

$ pmap 6649 | head -1
6649: /usr/lib64/firefox/firefox
1
# ls -la /proc/ID_GOES_HERE/exe

Example:

# ls -la /proc/1374/exe
lrwxrwxrwx 1 chmm chmm 0 Mai 5 20:46 /proc/1374/exe -> /usr/bin/telegram-desktop
4

You can Also use awk in combination with ps

ps aux | awk '$2 == PID number for a process { print $0 }'

example:

root@cprogrammer:~# ps aux | awk '$2 == 1 { print $0 }'
root 1 0.0 0.2 24476 2436 ? Ss 15:38 0:01 /sbin/init 

to print HEAD LINE you can use

 ps --headers aux |head -n 1 && ps aux | awk '$2 == 1 { print $0 }' (or) ps --headers aux |head -n 1; ps aux | awk '$2 == 1 { print $0 }'
root@cprogrammer:~# ps --headers aux |head -n 1 && ps aux | awk '$2 == 1 { print $0 }'
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 24476 2436 ? Ss 15:38 0:01 /sbin/init
3

Simmilar to slhck's Answer, but relying on file operations instead of command invocations:

MYPID=1
cat "/proc/$MYPID/comm"
1

Surprisingly, no one has mentioned the -f (full command) option for ps. I like to use it with -e (everything) and pipe the results to grep so I can narrow my search.

ps -ef | grep <PID>

This is also very useful for looking at full commands that someone is running that are taking a lot of resources on your system. This will show you the options and arguments passed to the command.

1

I find the easiest method to be with the following command:

ps -awxs | grep pid
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy