All running programs linux

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).

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.

Читайте также:  Установка пакетов deb kali linux

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.

Читайте также:  Как разблокировать root astra linux

Источник

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.

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.
Читайте также:  How to check linux packages

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