Blog

03/06/2019

Linux find process by name



I am a new Linux user. How can I find a computer program/process by name on Linux? Is it possible to find a process by name instead of PID on a Linux?

A Linux computer program, or running a program concurrently with other applications known as a process. A child process in Linux is a process created by another process. The parent process is a process that has created one or more child processes on Linux operating system. The process identifier (process ID or PID) is a number used by Linux or Unix operating system kernels. It is used to uniquely identify an active process.

Procedure to find process by name on Linux

  1. Open the terminal application.
  2. Type the pidof command as follows to find PID for firefox process:
    pidof firefox
  3. Or use the ps command along with grep command as follows:
    ps aux | grep -i firefox
  4. To look up or signal processes based on name use:
  5. pgrep firefox

Linux find process by name using pgrep command

pgrep command looks through the currently running processes and lists the process IDs which match the selection criteria to screen. All the criteria have to match. For example, will only list the processes called sshd AND owned by root user:
$ pgrep -u root sshd
Just look up pid for firefox process:
$ pgrep firefox

How to use ‘ps aux | grep command’

ps command shows information about a selection of the active processes:
$ ps aux
$ ps aux | grep -i 'search-term'
$ ps aux | grep 'firefox'
$ ps aux | grep 'sshd'

OR use the following syntax instead of using egrep command in pipes:
$ ps -fC firefox
$ ps -fC chrome

The -C option asks ps command to select PIDs by command name.

Using pidof command to grab PIDs for any named program on Linux

The pidof command finds the process id’s (pids) of the named programs such as sshd, firefox and more. For example:
$ pidof sshd
$ pidof firefox

Sample outputs:

A note about top/htop command

To display Linux processes use top command or htop command:
$ top
OR
$ htop

See also

Getting more help

Read the man pages for the following command using man command:
$ man pgrep
$ man pidof
$ man ps

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

20/08/2019

Start your Bitcoin Exchange with our Software

Start your Bitcoin Exchange with our Software Setup your white label bitcoin exchange right away. Or create your own cryptocurrency using...
14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....