- Linux find process by name
- Procedure to find process by name on Linux
- Linux find process by name using pgrep command
- How to use ‘ps aux | grep command’
- Using pidof command to grab PIDs for any named program on Linux
- A note about top/htop command
- See also
- Getting more help
- How to check running process in Linux using command line
- Check running process in Linux
- How to manage processes from the Linux terminal
- Linux pgrep command
- Linux top command
- Linux htop command to check running process in Linux
- Linux kill command
- Linux pkill command
- Linux killall command
- Linux nice and renice command
- How to find the Process ID of a program in Linux
- What is process ID (PID)?
- What is parent process ID (PPID)?
- 1) Finding a process ID (PID) with pidof command
- 2) How to search a process ID (PID) in Linux, using pgrep command?
- 3) locating a process ID (PID) with pstree
- 4) How to find a process ID (PID) using ps command?
- 5) Finding a process ID (PID) using ss command
- 6) Finding a process ID (PID) with netstat command
- 7) How to find a process ID (PID) in Linux, using lsof command?
- 8) Searching a process ID (PID) using fuser command
- 9) How to find a process ID (PID) in Linux, using systemctl command?
- Conclusion
Linux find process by name
Procedure to find process by name on Linux
- Open the terminal application.
- Type the pidof command as follows to find PID for firefox process:
pidof firefox - Or use the ps command along with grep command as follows:
ps aux | grep -i firefox - To look up or signal processes based on name use:
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.
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
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
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to check running process in Linux using command line
I am a new system administrator for the Linux operating system. How do I check running process in Linux using the command line option?
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Linux terminal |
Est. reading time | 4 mintues |
One can use the Linux command line or terminal app to display a running process, change their priorities level, delete process and more. This page shows how to use various commands to list, kill and manage process on Linux.
Check running process in Linux
The procedure to monitor the running process in Linux using the command line is as follows:
- Open the terminal window on Linux
- For remote Linux server use the ssh command for log in purpose
- Type the ps aux command to see all running process in Linux
- Alternatively, you can issue the top command or htop command to view running process in Linux
Let us see some example and usage in details.
Please note that vivek@nixcraft:
$ is my shell prompt. You need to type commands after the $ prompt.
How to manage processes from the Linux terminal
The ps command is a traditional Linux command to lists running processes. The following command shows all processes running on your Linux based server or system:
vivek@nixcraft:
$ ps -aux
vivek@nixcraft:
- root – User name
- 1 – PID (Linux process ID)
- 19:10 – Process start time
- /sbin/init splash – Actual process or command
There may be too many processes. Hence, it uses the following less command/more command as pipe to display process one screen at a time:
vivek@nixcraft:
$ ps -aux | more
vivek@nixcraft:
$ sudo ps -aux | less
Press q to exit from above Linux pagers. You can search for a particular Linux process using grep command/egrep command:
vivek@nixcraft:
$ ps aux | grep firefox
vivek@nixcraft:
$ sudo ps aux | grep vim
vivek@nixcraft:
$ sudo ps -aux | egrep ‘sshd|openvpn|nginx’
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Linux pgrep command
Many variants of Linux comes with the pgrep command to search/find process. The syntax is:
vivek@nixcraft:
$ sudo pgrep sshd
vivek@nixcraft:
$ pgrep vim
vivek@nixcraft:
$ pgrep firefox
vivek@nixcraft:
Linux top command
The top command is another highly recommended method to see your Linux servers resource usage. One can see a list of top process that using the most memory or CPU or disk.
vivek@nixcraft:
$ sudo top
vivek@nixcraft:
Linux htop command to check running process in Linux
The htop command is an interactive process viewer and recommended method for Linux users. One can see a list of top process that using the most memory or CPU or disk and more:
vivek@nixcraft:
$ sudo htop
vivek@nixcraft:
Linux kill command
Want to kill a process? Try kill command. The syntax is:
vivek@nixcraft:
$ kill pid
vivek@nixcraft:
$ kill -signal pid
Find PID using ps, pgrep or top commands. Say you want to kill a PID # 16750, run:
vivek@nixcraft:
$ kill 16750
For some reason if the process can not be killed, try forceful killing:
vivek@nixcraft:
$ kill -9 16750
OR
vivek@nixcraft:
$ kill -KILL 16750
Linux pkill command
If you wish to kill a process by name, try pkill command. The syntax is:
vivek@nixcraft:
$ pkill processName
vivek@nixcraft:
$ pkill vim
vivek@nixcraft:
$ pkill firefox
vivek@nixcraft:
$ pkill -9 emacs
vivek@nixcraft:
$ sudo pkill -KILL php7-fpm
Linux killall command
The killall command kills processes by name, as opposed to the selection by PID as done by kill command:
vivek@nixcraft:
$ killall vim
vivek@nixcraft:
$ killall -9 emacs
Linux nice and renice command
The primary purpose of the nice command is to run a process/command at a lower or higher priority. Use the renice command to alter the nice value of one or more running Linux processes. The nice value can range from -20 to 19, with 19 being the lowest priority. Say, you want to compile software on a busy Linux server. You can set a very low priority, enter:
vivek@nixcraft:
$ nice -n 13 cc -c *.c &
Set a very high priority for a kernel update. Before rebooting Linux server, run:
Источник
How to find the Process ID of a program in Linux
When working on a Linux system, sometimes you need to figure out what processes are running and which PID or PPID is tied to it. It can be used for several purposes.
Basically, we search for a PID in Linux to kill an unresponsive program, which can be done by the GUI task manager, but CLI is the most efficient way to handle unresponsive programs.
This is better than the GUI, because sometimes GUI-based tools may not show the still running hidden process.
In this tutorial, we will show you how to find the process ID (PID) of a program running in many ways in Linux.
What is process ID (PID)?
PID refers to process ID, which is commonly used by most operating system kernels, such as Linux, Unix, MacOS and Windows.
This is a unique ID that is automatically assigned to each process when it is created. A process is a running instance of a program.
What is parent process ID (PPID)?
A parent process is a process that has created one or more child processes. Each child process is given a Parental Process ID (PPID), and the parent process kills the child when it completes their operation.
You may be interested to read the below articles, as these are related to this topic.
Each time the process ID is changed for all processes except init. The init process is always the first process in the system and the ancestor of all other processes, it holds PID 1.
The default maximum value of PIDs is 32768 on 32-bit machine. And you can set the value higher on 64-bit systems up to 2^22 (approximately 4 million). This can be verified by running the following command on your machine:
You may ask, why do we need such large number of PIDs? This is because PIDs cannot be reused immediately and also to prevent potential errors.
You can find the PID of processes running on the system using the below nine command.
- pidof: pidof – find the process ID of a running program.
- pgrep: pgre – look up or signal processes based on name and other attributes.
- ps: ps – report a snapshot of the current processes.
- pstree: pstree – display a tree of processes.
- ss: ss is used to dump socket statistics.
- netstat: netstat is displays a list of open sockets.
- lsof: lsof – list open files.
- fuser: fuser – list process IDs of all processes that have one or more files open
- systemctl: systemctl – Control the systemd system and service manager
To prove this, we are going to find the Apache process ID. Make sure to enter your process name instead of ours.
1) Finding a process ID (PID) with pidof command
The pidof command is used to find the process ID of the running program. It prints those IDs into the standard output. To demonstrate this, we will be finding the ‘Apache2’ process id in the system.
In the above output you may have difficulties identifying the process ID because it displays all PIDs (including parent and child) against the process name.
So we need to find the Parent Process PID (PPID), which is what we are looking for. This will be the first number. In my case it is 3754 and it is sorted in descending order.
2) How to search a process ID (PID) in Linux, using pgrep command?
The pgrep command looks at the processes currently running, and lists the process IDs that match the selection criteria.
The above output is similar to the ‘pidof’ command output, but it sorted the results in ascending order, which clearly shows that the parent process PID is standing at last.In my case it is 3754 .
Note: Identifying the parent process ID can be problematic when using the ‘pidof’ & ‘pgrep’ command, as each process comes with a single PPID and multiple PIDs which doesn’t show a clear demarcation between them. Hence please exercise caution while looking at the results.
3) locating a process ID (PID) with pstree
The pstree command shows running processes as a tree-like format which is very convenient way to display the process hierarchy and makes the output more visually appealing. If a user name is specified in the pstree command then it shows all the processes owned by the respective user.
pstree visually merges identical branches by putting them in square brackets and prefixing them with the repetition count.
To get only the parent process, use the following format.
‘pstree’ command is much better than the ‘pidof’ & ‘pgrep’ commands, because it separates parent from the child processes which is not possible by them.
4) How to find a process ID (PID) using ps command?
The ps command displays information about a selection of the active processes which includes the process ID (pid=PID), terminal associated with the process (tname=TTY), cumulated CPU time in [DD-]hh:mm:ss format (time=TIME), and executable name (ucmd=CMD). Output is unsorted by default.
The Parent Process ID (PPID) can be easily identified based on the process start date from the above output. In our case the ‘Apache2’ process started on December 11th , which is the parent process and the others are the child processes. The PID of Apache2 is 3754 .
5) Finding a process ID (PID) using ss command
The ss command is used to dump socket statistics. It allows showing information similar to netstat. It can display more TCP and state information than other tools.
It can display stats for all kind of sockets such as PACKET, TCP, UDP, DCCP, RAW, Unix domain, etc.
6) Finding a process ID (PID) with netstat command
The netstat command is used to print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. By default, netstat displays a list of open sockets.
If you don’t specify any address families, then the active sockets of all configured address families will be printed. This program is obsolete. Replacement for netstat is ss.
7) How to find a process ID (PID) in Linux, using lsof command?
The lsof command is used to list open files. The Linux lsof command lists information about files that are open by processes running on the system.
8) Searching a process ID (PID) using fuser command
The fuser utility shall write to standard output, the process IDs of processes running on the local system that have one or more named files open.
9) How to find a process ID (PID) in Linux, using systemctl command?
The systemctl command is used to control the systemd service manager. This is a replacement for the old SysVinit system management, and most of the modern Linux operating systems have been moved to the systemd.
Conclusion
We have shown you several command to find out the PIDs of a specific running program in Linux.
If you have questions, feel free to leave a comment below.
Источник