Linux finding running processes

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.

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.

Читайте также:  Man команда в линукс

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.

Источник

How to Use the ps Command to Find Running Processes on Linux

The full form of ps is process status. It is a command used to find information about currently running processes on Linux. ps is a very important command of Linux.In this article, I will show you how to use the ps command to find running processes on Linux. So, let’s get started.

Different Types of Options:

The ps command accepts different options.

Читайте также:  Linux usb formatting tools

    UNIX options – have leading dash.

In this example, I will use the UNIX and at times GNU options. But the BSD options are similar. Most of the time, you can mix them together without any problems. Although, you can’t mix some of the options together as it won’t work. So, be careful.

Finding All Running Processes:

With ps command, you can find all the running processes on your machine.

To find all the running processes with ps, use ps as follows,

As you can see, the UID (User ID), PID (process ID), PPID (parent process ID), CMD (command used to run the process) and some other information about all the running processes are displayed.

You can list all the running processes with different ps options combination. They will show different information about the running processes. You can actually tell ps to display specific information, which we will get to in the later section.

As you can see, ps -e shows the PID, TTY (terminal number), TIME (process running time) and CMD of the running processes. That’s a lot less information than earlier.

It shows a lot of information about the running processes, but some of the columns such as C (processor utilization), SZ (size in physical pages), RSS (resident set size), PSR (processor that process is currently assigned to), STIME (the time when the process started) etc. are not displayed. So, it’s a little bit more compact than ps -eF.

This one shows you UID (user ID), PRI (current priority of the process), NI (nice value) as well. So, it’s really handy.

Making ps Navigation Easy:

A typical Linux system has a lot of process running in the background. So, the output of the ps command is very long. It is harder to find useful information there. But, we can use a pager such as less to look for the processes a little bit easier.

You can use the less pager as follows:

The output of ps will be opened with less.

Now, you can use and arrow keys to navigate the list very easily.

You can also search for specific keywords here. This is really helpful for finding the processes that you’re looking for.

To search for a processes, let’s say acpi, type in the keyword as follows in the less pager.

As you can see, the process with the keyword acpi is highlighted.

You can also press n and p keys to go to the next and previous match (if available) respectively.

As you can see, I pressed n to and the next process with the keyword acpi is highlighted.

To exit out of the pager, press q.

Manually Select Columns to Display in ps:

The ps -e / ps -ef / ps -eF etc command shows some default columns. But, if you want, you can tell ps to show you specific columns, or add additional columns to the default set of columns.

For example, let’s say, you want to see only %MEM (percent memory usage), PID (process ID) and UID (process owner ID) and COMMAND (process command), then run ps as follows:

Читайте также:  Установка линукс локального сервера

As you can see, ps displayed only the information that I asked it for. Nothing more, nothing less.

The column keywors used here are %mem (for %MEM), pid (for PID), uid (for UID), comm (for COMMAND). ps supports a lot of keywords. You can find the whole list in the man page of ps.

Just open the man page of ps with the following command and navigate to the STANDARD FORMAT SPECIFIERS section as shown in the screenshot below.

If you want to display additional columns along with the default set of columns, then you can use the -O option to specify the columns that you want to see.

As you can see, I added %CPU and %MEM column along with the default columns of ps -ef command.

Sorting Output of ps Command:

You can also sort the output of ps according to any specific column or columns. You can sort the output of ps in the ascending or descending order depending on your requirement.

To sort the output of ps using any single column, you can use ps as follows:

Some example will make it clearer.

Let’s say, you want to sort the processes depending on how long the process is running in ascending order. You can run ps as follows:

NOTE: The default is sorting in ascending order. So you can omit the + sign if you want.

As you can see, the output is sorted in the ascending order by the TIME column.

Again, let’s say, you want to sort the processes depending on how long the process is running in the descending order. Then, the ps command would be:

As you can see, the processes that are running for the longest is listed first.

If you want to sort by multiple columns, just add the columns as follows:

Where to Go Next?

I’ve covered the basics of the ps command. Now, you should be able to learn more about the ps command from the man page of ps.

You can access the man page of ps as follows,

For example, you can find specific process if you know it’s PID using ps as follows:

NOTE: Here, 2060 is the PID of the process.

You can also search for processes owned by specific user or group etc as well.

For example, to find all the running processes of your login user, run ps as follows:

NOTE: You can replace $(whoami) with any username you want to list processes running as that user.

So, that’s how you use ps command to find running processes on Linux. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.

Источник

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