Find the running processes in linux

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:

  1. Open the terminal window on Linux
  2. For remote Linux server use the ssh command for log in purpose
  3. Type the ps aux command to see all running process in Linux
  4. 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:

  1. root – User name
  2. 1 – PID (Linux process ID)
  3. 19:10 – Process start time
  4. /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 do I count how many processes are running in Linux?

Viewing running processes in Linux

The ps command used to list the currently running processes and their PIDs in Linux and Unix-like systems. At a bare minimum, two processes displayed on the screen. For example, bash and ps might default on Linux when you just type ps command ps
Sample outputs:

Counts for each file in Linux

The wc is an acronym for word count. By default, wc command counts the number of lines, words, and characters in the text. For examples, show the newline counts
echo «line 1» | wc -l
To print the byte counts
echo «Hello» | wc -c
One can print the word counts as follows:
echo «Hello world» | wc -w

  • 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

Find how many processes are running in Linux

One can use the ps command along with with the wc command to count the number of processes running on your Linux based system by any user. It is best to run the following commands as root user using the sudo command.

Command to count the number of processes running in Linux

The Linux syntax is as follows:
# ps -e | wc -l
To see and count every process on the system using BSD syntax:
# ps axu | wc -l
Want to see and count every process running as vivek (real and effective ID) in user format, run:
$ ps -U vivek -u vivek u | wc -l
Another example for www-data user:
$ ps -U www-data -u www-data u | wc -l
In short to see and count only processes by a certain user naned root, you can use the following command:
sudo ps -U root | wc -l
sudo ps -U root -u root u | wc -l
Next we are going count process IDs of nginx using the following syntax:
ps -C nginx | wc -l
ps -C nginx -o pid= | wc -l

Pass the —no-headers or —no-heading to print no header line at all to get processes count correctly on Linux:
# ps -e —no-headers | wc -l
52
# ps -e | wc -l
53
When count real number of nginx it is a good idea to remove grep command while grepping using ps command:
ps -e —no-headers | grep [n]ginx
ps -e —no-headers | grep [n]ginx | wc -l

Understanding the wc command options

wc option description
-c Print the byte counts
-m Print the character counts
-l Print the newline counts
-w print the word counts
—help Display the wc command help and exit

Understanding the ps command options

ps option description
-e Select all processes (GNU/Linux syntax)
aux Select all processes using BSD syntax
-U user Select by real user ID (RUID) or name
-u user Select by effective user ID (EUID) or name
-C cmdlist Select by command name. This selects the processes whose executable name is given in cmdlist
—no-headers Print no header line at all. —no-heading is an alias for this option

Conclusion

You learned how to list the number of processes running on the Linux or Unix like system using various command-line options. See the gnu ps help page here.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

How to Find and Kill Running Processes in Linux

Process management is one of the important aspects of System Administration in Linux, and it includes killing of processes using the kill command.

Find and Kill Running Processes in Linux

In this how-to, we shall look at killing of less productive or unwanted processes on your Linux system.

What is a Process in Linux?

A process on a Linux system can be a running occurrence of an application or program. You can also refer to processes as tasks executing in the operating system.

When a process is running, it keeps on shifting from one state to another and a process can in one of the following states:

  1. Running: meaning the process is either executing or it is just set to be executed.
  2. Waiting: meaning that the process is waiting for an event or for a system resource to carry out a task.

There are two types of waiting process under Linux namely interruptible and uninterruptible.

A waiting process that can be interrupted by signals is called Interruptible, while a waiting process that is directly waiting on hardware conditions and cannot be interrupted under any conditions is called uninterruptible.

  1. Stopped: meaning that the process has been stopped, using a signal.
  2. Zombie: meaning the process has been stopped abruptly and is dead.

With this brief overview let us now look at ways of killing processes in a Linux system. We’ve already covered a few articles on ways to kill Linux running processes us using kill, pkill, killall and xkill, you can read them below.

When killing processes, the kill command is used to send a named signal to a named process or groups of processes. The default signal is the TERM signal.

Remember that the kill command can be a built-in function in many modern shells or external located at /bin/kill.

How to Find Process PID in Linux

In Linux every process on a system has a PID (Process Identification Number) which can be used to kill the process.

You can identify the PID of any process by using the pidof command as follows:

Find Process PID in Linux

How to Kill Processes in Linux

Once you find the process PID, let us now look at how to kill processes. In this first example, I am going to first get the PID of the process and then send a signal to it.

I want to kill gimp process, so I will do it as follows:

To verify that the process has been killed, run the pidof command and you will not be able to view the PID.

Kill Linux Process PID

You can also send a named signal to the process by using the signal name or numbers as follows:

Kill Process PID by Signal

Using the signal number to kill a process:

Kill Process PID by Number

In the above example, the number 9 is the signal number for the SIGKILL signal.

How to Kill Multiple Process PID’s in Linux

To kill more than one process, pass the PID(s) to the kill command as follows:

Kill Multiple Linux Process PID’s

Summary

There are many other ways of killing processes in Linux, these few examples just help to give you an overview of killing processes. Do let us know how you kill processes in Linux? and also tell other ways if any via comments.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Читайте также:  Что делать с экраном смерти linux
Оцените статью