How to get pid by unique process name in linux?


by mohammad , in category: General Help , 25 days ago

How to get pid by unique process name in linux?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by anissa , 23 days ago


In Linux, you can use the pgrep command to retrieve the process id (pid) associated with a unique process name. Here's how you can do it:

  1. Open the terminal.
  2. Run the following command: pgrep process_name Replace process_name with the name of the unique process you are looking for. For example, if you want to find the pid of the Apache web server, you would run: pgrep apache2
  3. The command will output the pid of the process. If multiple processes with the same name are found, it will display all the pids in separate lines.

You can also use the -f option with pgrep to match the full command line instead of just the process name. This can be useful if you need to find a process running with specific arguments.


pgrep -f "python3"

This command will find the pid of a Python script named "" running with the command "python3".

Note that pgrep is available on most Linux distributions, but if it's not installed in your system, you can usually install it using the package manager specific to your distribution.