Linux find all processes running

How to List Running Processes in Linux and Manage them

List processes Linux — Developers utilize a variety of applications and run commands in the terminal on a daily basis.
On your Linux system, each application you use or command you perform produces a process or task. To guarantee optimal system performance, you will need to control processes as a system administrator.

Multitasking is one of the most appealing features of the Linux operating system, as well as modern computers in general. As a result, numerous programs can run simultaneously.

What are processes in Linux?

When you perform a command or open an application in Linux, it starts a process. Applications, on the other hand, generate and execute several processes for various tasks, whereas commands only create one.

When you launch your Visual Studio Code editor, for example, you start a process that will only cease (or die) when you exit or terminate the Visual Studio Code application.

Similarly, when you run a command in the terminal (such as curl ifconfig.me), it starts a process that will only terminate when the command completes or is terminated.

Each new process starts as a foreground process by default. This implies that it must be completed before a new process may begin. Processes running in the background allow you to work on other things at the same time.

List running processes in Linux

Use one of the three commands to list processes in Linux:

  • ps displays a list of all processes; it can also be used with options to get a more detailed output.
  • top displays a live list of currently active processes and allows you to interact with them by killing, stopping, changing priority, and so on.
  • htop instantaneous results on a user-friendly output with the opportunity to engage with the process

Utilizing ps as a command

The ps command (process statuses) creates a snapshot of all currently active processes. As a result, unlike the Windows task manager, the outcomes are predictable.

The syntax for the ps command is as follows:

The following are some of the most commonly used ps command options:

  • a: Make a list of all processes that are causing problems for all users.
  • -A, -e: Display a list of all the processes on the system.
  • -a: List all processes, excluding session leaders (those whose process ID is the same as the session * ID) and those not associated with a terminal.
  • -d: Except for session leaders, list all processes.
  • –deselect, — N: Remove any processes that do not meet a user-defined condition from the list.
  • f: Uses ASCII art to display the process hierarchy.
  • -j: Shows the output in jobs format.
  • T: Make a list of all the processes that are connected to this terminal.
  • r: Only list processes that are currently active.
  • u: Increase the size of the output to include more information, such as CPU and memory use.
  • -u: Define a user for whom you want to list processes.
  • x: Processes without a TTY are included.
Читайте также:  Настройки панелей в линукс

Running the ps command without any options produces an output similar to

The following categories are included in the default output:

  • PID: Process Identification Number
  • TTY: The terminal on which the process is operating.
  • TIME: The total amount of time spent on the computer (CPU usage total amount).
  • CMD: The name of the command that started the process

Using the a, u, and x options together produces a more detailed output

The extended output now includes the following new categories:

  • USER: This is the name of the person who is executing the process.
  • %CPU: The proportion of time that the CPU is in use.
  • %MEM: The proportion of memory used.
  • VSZ: The process’s total virtual memory usage in kilobytes.
  • RSS: “stands for Resident Set Size”, which refers to the amount of RAM used by a process.
  • STAT: The current state of the process.
  • START: The time when the process began.

To show the currently executing processes in a hierarchical order.

Using the top command in Linux, you can get a list of currently running processes

The top command provides a list of currently active processes in decreasing CPU consumption order. This means that the processes that use the most resources are at the top of the list:

With the default refresh rate of three seconds, the output of the top command refreshes in real time. The following categories appear in the output of the top command:

  • PID (Process Identification Number): This is a number that identifies a
  • USER: This is the name of the person who is executing the process.
  • PR: The process’s scheduling priority.
  • NI: The process’s nice value, with lower values signifying higher importance.
  • VIRT: The amount of virtual memory used by the process.
  • RES: The amount of resident (physical) memory that the process uses.
  • SHR: The process’s total shared memory use.
  • R (running) or S (sleeping): The status of the process
  • %CPU: The percentage of time that the CPU is in use.
  • %MEM: The memory usage percentage
  • TIME+: The total amount of CPU time used.
  • COMMAND: The command that initiated the procedure.

Use the following options to interact with the top command or modify the output format while it is running:

  • c: Show the process path in its entirety.
  • d: Set the output refresh rate to a custom value (in seconds).
  • h: Bring up the help menu.
  • k: Provide the PID to kill a process.
  • M: Sort the list by the amount of memory used.
  • N: Sort the list according to the PID.
  • r: Provide the PID to change the nice value (priority) of a process.
  • z: Highlight running processes by changing the output color.
  • q: Exit the command prompt.

Using the htop command in Linux, you may see what processes are currently running.

The htop command produces the same results as the top command, but in a more user-friendly and understandable manner.

Читайте также:  Usb virtualbox linux ubuntu

Because this command isn’t included in most Linux distributions, you’ll need to install it yourself:

command provides the following output:

List Processes Linux

To interact with the htop command, press the following keys:

Scroll the process list vertically and horizontally using the directional keys.

  • F1: Displays the help menu.
  • F2: Open the htop command setup
  • F3: Type the name of a process to find it.
  • F4: Sort the list of processes by name.
  • F5: Select whether the process hierarchy is displayed as a sorted list or a tree.
  • F6: Sort processes by columns
  • F7: Lower a process’s nice value (raise its priority).
  • F8: Lower the process’s nice value (lower its priority).
  • F9: Terminate the currently selected process.
  • F10: Closes the command prompt.

Conclusion

Knowing how to list all running processes in your Linux operating system is critical. When you need to manage processes, this expertise will come in handy.
To customize the output and command behavior, use the available command options.

2 comments on “How to List Running Processes in Linux and Manage them ”

[…] Process Manager, or fpm in PHP, is a pattern of execution with various capabilities that have a significant impact […]

Источник

Linux List Processes – How to Check Running Processes

Bolaji Ayodeji

Bolaji Ayodeji

Linux List Processes – How to Check Running Processes

Every day, developers use various applications and run commands in the terminal. These applications can include a browser, code editor, terminal, video conferencing app, or music player.

For each of these software applications that you open or commands you run, it creates a process or task.

One beautiful feature of the Linux operating system and of modern computers in general is that they provide support for multitasking. So multiple programs can run at the same time.

Have you ever wondered how you can check all the programs running on your machine? Then this article is for you, as I’ll show you how to list, manage, and kill all the running processes on your Linux machine.

Prerequisites

  • A Linux distro installed.
  • Basic knowledge of navigating around the command-line.
  • A smile on your face 🙂

A Quick Introduction to Linux Processes

A process is an instance of a running computer program that you can find in a software application or command.

For example, if you open your Visual Studio Code editor, that creates a process which will only stop (or die) once you terminate or close the Visual Studio Code application.

Likewise, when you run a command in the terminal (like curl ifconfig.me ), it creates a process that will only stop when the command finishes executing or is terminated.

How to List Running Processes in Linux using the ps Command

You can list running processes using the ps command (ps means process status). The ps command displays your currently running processes in real-time.

To test this, just open your terminal and run the ps command like so:

Screenshot-2021-06-28-at-3.25.33-PM

This will display the process for the current shell with four columns:

  • PID returns the unique process ID
  • TTY returns the terminal type you’re logged into
  • TIME returns the total amount of CPU usage
  • CMD returns the name of the command that launched the process.

You can choose to display a certain set of processes by using any combination of options (like -A -a , -C , -c , -d , -E , -e , -u , -X , -x , and others).

If you specify more than one of these options, then all processes which are matched by at least one of the given options will be displayed.

Читайте также:  Linux интернет ограничение скорости интернета

Screenshot-2021-06-28-at-3.55.10-PM

Type man ps in your terminal to read the manual for the ps command, which has a complete reference for all options and their uses.

To display all running processes for all users on your machine, including their usernames, and to show processes not attached to your terminal, you can use the command below:

Here’s a breakdown of the command:

Screenshot-2021-06-28-at-4.39.05-PM

  • ps : is the process status command.
  • a : displays information about other users’ processes as well as your own.
  • u : displays the processes belonging to the specified usernames.
  • x : includes processes that do not have a controlling terminal.

This will display the process for the current shell with eleven columns:

  • USER returns the username of the user running the process
  • PID returns the unique process ID
  • %CPU returns the percentage of CPU usage
  • %MEM returns the percentage memory usage
  • VSV returns the virtual size in Kbytes
  • RSS returns the resident set size
  • TT returns the control terminal name
  • STAT returns the symbolic process state
  • STARTED returns the time started
  • CMD returns the command that launched the process.

How to List Running Processes in Linux using the top and htop Commands

You can also use the top task manager command in Linux to see a real-time sorted list of top processes that use the most memory or CPU.

Type top in your terminal and you’ll get a result like the one you see in the screenshot below:

Screenshot-2021-06-28-at-4.27.28-PM

An alternative to top is htop which provides an interactive system-monitor to view and manage processes. It also displays a real-time sorted list of processes based on their CPU usage, and you can easily search, filter, and kill running processes.

htop is not installed on Linux by default, so you need to install it using the command below or download the binaries for your preferred Linux distro.

sudo apt update && sudo apt install htop

Just type htop in your terminal and you’ll get a result like the one you see in the screenshot below:

Screenshot-2021-06-29-at-4.49.09-AM

How to Kill Running Processes in Linux

Killing a process means that you terminate a running application or command. You can kill a process by running the kill command with the process ID or the pkill command with the process name like so:

To find the process ID of a running process, you can use the pgrep command followed by the name of the process like so:

To kill the iTerm2 process in the screenshot above, we will use any of the commands below. This will automatically terminate and close the iTerm2 process (application).

Conclusion

When you list running processes, it is usually a long and clustered list. You can pipe it through less to display the command output one page at a time in your terminal like so:

or display only a specific process that matches a particular name like so:

I hope that you now understand what Linux processes are and how to manage them using the ps , top , and htop commands.

Make sure to check out the manual for each command by running man ps , man top , or man htop respectively. The manual includes a comprehensive reference you can check if you need any more help at any point.

Thanks for reading – cheers! 💙

Источник

Оцените статью
Adblock
detector