In this article, we will look at how to find a process name by its process identification number (PID). Before we dive into the actual solution, let’s briefly talk about how processes are created and identified in Linux.
Every time a user or the system (Linux) launches a program, the kernel creates a process. A process holds execution details of the program in memory, such as its input and output data, variables, and more.
Importantly, since Linux is a multitasking operating system, it executes several programs simultaneously, which means each process must be identified specifically.
The kernel identifies each process using a process ID (PID). Every instance of a process must have a unique PID, which is assigned when the process is invoked. This avoids any execution errors.
The /proc file system stores information about currently running processes on your system, it contains directories for each process.
List /proc File System
You can use the ls command to list its contents, however, the list may be long, so employ a pipeline and the less utility to view the /proc contents in a more convenient way as below:
ls /proc OR ls /proc | less

The numbered directories store information files about the processes in execution, with each number corresponding to a PID.
Show SystemD Process PID
Below is an example of listing the files for the systemd process with PID 1
.
ls /proc/1

Monitor Processes Using Commands
You can monitor processes and their PIDs using traditional Linux commands such as ps, top, and the relatively new glances command, plus many more,e as in the examples below:
Using ps
command, which will show a list of running processes, including their PID:
ps aux

Using top
command, which will provide a real-time interactive view of running processes:
top

Using glances
command, which will show real-time usage of various aspects of your system, such as CPU, memory, and disk:
glances

Find Out Process PID Number
To find out the PID of a process, you can use pidof
, a simple command to print out the PID of a process:
pidof firefox pidof python pidof cinnamon

Find Process Name Using PID
Coming back to our point of focus, assuming you already know the PID of a process, you can print its name using the command form below:
ps -p PID -o format
Where:
-p
specifies the PID-o
format enables a user-defined format
Now, let’s focus on finding the process name using its PID number with the help of a user-defined format i.e comm=
which means the command name, same as the process name.
ps -p 2523 -o comm= ps -p 2295 -o comm=

For additional usage information and options, look through the ps man page.
man ps
If you want to kill a process using its PID number, I suggest you read Find and Kill Linux Processes Using its PID.
That’s it for the moment! If you know any other better way to find out a process name using its PID, feel free to share with us in the comments section below.