> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Find Process Name from its PID
- URL: https://linuxhandbook.com/process-name-from-pid/
- Published: 2022-02-26T03:50:00.000Z
- Updated: 2023-09-16T09:21:40.000Z
- Description: If you know the PID of a process, here's how to get the process name in Linux command line.
- Author: Hunter Wittenborn
- Tags: Process Handling, Quick Tip, #docs-col, #cli

If you know the process ID (PID), you can get the process name using the ps command:

```
ps -p PID -o comm=
```

The ps command is used for process related operations. In the above command, `-p PID` provides the process ID and `-o comm=` asks it to output the command associated with the given PID.

Here's an actual example:

![Get process name from process ID](https://linuxhandbook.com/content/images/2022/02/image-1.png)

Honestly, it's difficult to remember the weird `ps -p PID -o comm=` syntax. And if that's the case, you may either look into the [man page](https://linuxhandbook.com/man-pages/) of ps command or use other ways of getting the details.

You can [list all running process using the ps command](https://linuxhandbook.com/ps-command/#2-see-all-running-processes-with-ps-aux-command) or top command and note the process ID and process name as desired.

![List all running processes in Linux](https://linuxhandbook.com/content/images/2022/02/list-all-process-ps-command-1.png)

If you know the PID, you can simply use the grep command to filter the output and get the details on that PID:

```
ps aux | grep PID
```

But as illustrated by the image below, the output gives other details along with the process name. 

![Use grep and ps command to get process name from PID](https://linuxhandbook.com/content/images/2022/02/use-grep-to-find-process-id-from-name.png)

That's not an issue if you are manually reading it. However, if you have to use it in a script, it could be an issue.

This is where the `ps -p PID -o comm=` is better.

**Bonus tip:** Since we are talking about process name and PIDs, let me quickly show you the reverse method, i.e., to [find PID from process name](https://linuxhandbook.com/find-process-id/).

There is a dedicated command called `pidof` and you can use it like this if you know the exact process name:

```
pidof exact_process_name
```

So, you just learned how to find process name from its PID in Linux command line and you also learned to get the PID from the process name.

If something isn't working right, or you just have any comments in general, feel free to leave any of it in the comments below.