Show all processes running in linux

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.
Читайте также:  What is x windows system in linux

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.

Читайте также:  Kali linux android apk

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 […]

Источник

Check Running Process in Linux

Want to know what all processes are running on your systems? Here’s how to get details of the running processes in Linux.

As a system administrator, you might need to check all the processes that are consuming your computer’s resources.

To get the list of all the running processes, run the ps command with aux argument flags in the following fashion:

This will give you a list of all running processes by all users on your system. You may use grep to filter the process using a pattern.

Let’s see about using it in detail. I’ll also share other commands to show running processes in Linux.

ps command

The ps command is the standard command that most sysadmins use in a UNIX-like operating system.

There are several options that you can use with the ps command, but the set of options to use when you want a list of all processes is aux .

So, running the following command will show me all processes on my system:

Or, you can use the BSD-style syntax, which are still available in GNU ps

  • a : Display information about other users’ processes as well as of the user’s own (if the processes are connected to terminals i.e. daemons get excluded)
  • u : Display in a user readable format
  • x : Include processes that are not connected to a terminal i.e. include daemons

This will give you an incredibly long list of running processes that were running at the time of executing the ps command.

Most people, including me, pipe this output in grep to find a needle in the haystack.

$ ps aux | grep alacritty pratham 4653 0.1 0.0 596776 63856 ? RNsl Mar09 3:43 alacritty pratham 4974 0.0 0.0 592792 58892 ? SNsl Mar09 0:18 alacritty pratham 6287 0.0 0.0 590204 56308 ? SNsl Mar09 0:14 alacritty pratham 8241 0.0 0.0 585504 51956 ? SNsl Mar09 0:07 alacritty pratham 514536 0.0 0.0 18808 2572 pts/1 SN+ 13:56 0:00 /usr/bin/grep --color=auto alacritty

Notice how the grep command was also included in the output. This is because it also has ‘alacritty’ in the process name (as the argument).

Читайте также:  Ping from interface linux

Be wary of this behaviour [that grep will be included in the output] if you use it in a script.

The only difference between using ps aux and ps -A is that when you use ps aux , you can easily grep the user, or alternatively, use the -u option. Whatever works for you.

Let’s see some other Linux commands to see running processes.

pgrep command

The pgrep command accepts a pattern to match and if there are any processes that match with the provided pattern, a process ID (PID) is returned to stdout.

Below is the syntax to use for pgrep command:

Let’s say, for example, I want to see the PIDs of any process that have the name ‘alacritty’. I would use the following command for that:

$ pgrep alacritty 4653 4974 6287 8241

As I ran that command, I got four PIDs indicating that four processes match with the pattern ‘alacritty’ and their PIDs are outputted to the stdout.

You can also use the -u flag (as opposed to u ) along with ps command to specify a particular user and filter out the results, making it easier to manage.

There might be multiple users on my computer using Vim, user pratham and root . If I want to filter processes and only want to see if pratham has an active Vim process or not, here is how I find it out.

$ ps -u pratham | grep vim 516525 pts/2 SNl+ 0:00 nvim

pstree command

The pstree command, as its name implies, shows a hierarchical view of parent processes and child processes.

partial output of pstree command

When run, the pstree will show a top-down, tree-like structure output of processes as shown in the picture above.

You can also note that the PID 1 is systemd, indicating that my Linux system uses systemd.

Since there is not much information about PID, user, start time, CPU usage etc, it is not exactly a «go-to» command. But it still helps to know which child process belongs to which parent process.

Use a system monitor

Any UNIX-like system will have a tool that you can use to monitor the usage of physical resources like CPU, RAM, Network etc.

A few tools that people prefer and are widely used are top , atop , htop and btop .

Here is the output of top command running on my computer. It shows information like total tasks, CPU and Memory usage.

picture of top command running

The atop command differs from top , obviously, but it also shows much more information about the processes like CPU, RAM usage, I/O etc.

picture of atop command running

The htop utility is a widely used resource monitoring utility to get a real-time bar of per-core CPU usage, RAM and swap.

picture of htop command running

Finally, btop is one of the newest addition to the system resource usage monitoring utilities. The best thing about it is that we get a history of CPU usage.

picture of btop command running

Conclusion

This article covers how you can view the processes running on your computer. And there are several methods of viewing it. But, the most preferred method is to use the ps command.

If you want an interactive view of the running processes (sorted by CPU usage or RAM usage etc), you can use a system monitor like top or htop.

Источник

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