Linux list processes all users

How to List Running Processes in Linux: A Beginner’s Guide

Need to view all running processes on your Linux server and discover which consumes your resources the most? Look no further, because, in this article, we’ll explain how to list Linux processes by using several common commands.

Introduction to Linux Processes

A process is the execution of a program. They can be launched when opening an application or when issuing a command through the command-line terminal.

A command can only generate a process. However, an application can run multiple processes for different tasks. For instance, Google Chrome will start a different process each time a new tab is opened.

Each Linux process is assigned a unique PID (process identification number). If there are no possible combinations left, the system can reuse old PIDs for newer processes.

A process can be initiated as a foreground or background process.

By default, all commands that run in the shell will start as foreground processes. As the process occupies the shell, you have to wait until it is finished before executing other commands.

If a command takes too long to complete, you can run it as a background process by adding an ampersand (&) at the end of the command so you can use the shell for other tasks.

Occasionally, processes may consume a lot of resources and need to be killed. Alternatively, times when you may want to change the priority level of a process, so the system will allocate more resources to it. Regardless of the case, all these tasks require you to do the same thing: listing the running processes on Linux.

How to List Running Processes in Linux?

There are several commands that you can use to list running processes: ps, top, and htop.

Utilizing the “ps” Command

The ps (process statuses) command produces a snapshot of all running processes. Therefore, unlike the Windows task manager, the results are static.

When this command is used without any additional argument or option, it will return a list of running processes along with four crucial columns: the PID, terminal name (TTY), running time (TIME), and the name of the command that launches the process (CMD). You can use ps aux to get more in-depth information about your running processes. Here’s a breakdown of each argument:

  • a option outputs all running processes of all users in the system.
  • u option provides additional information like memory and CPU usage percentage, the process state code, and the owner of the processes.
  • x option lists all processes not executed from the terminal. A perfect example of this are daemons, which are system-related processes that run in the background when the system is booted up.

If you want to list Linux processes in a hierarchical view, use the ps -axjf command. In this format, the shell will put child processes under their parent processes. Aside from those two options, here are some other common examples of the ps command that list running processes in Linux:

  • ps -u [username] lists all running processes of a certain user.
  • ps -e or ps -A displays active Linux processes in the generic UNIX format.
  • ps -T prints active processes that are executed from the terminal.
  • Ps -C process_name will filter the list by the process name. In addition, this command also shows all child processes of the specified process.

Using the “top” Command

The top command is used to discover resource-hungry processes. This Linux command will sort the list by CPU usage, so the process which consumes the most resources will be placed at the top.

Читайте также:  Лицензия windows oa cis and ge

Unlike the ps command, the output of the top command is updated periodically. That means you’ll see real-time updates for CPU usage and running time. Once the shell returns the list, you can press the following keys to interact with it:

Keys Functions
k Kills a process
M Sorts the list by memory usage.
N Sorts the list by PID.
r Changes the priority of a process.
h Displays the help window.
z Displays running processes in colors.
d Changes the refresh time interval.
c Displays the absolute path of a process.
CTRL+C or q Stops the top command.

Keep in mind that the keys above are case sensitive, so be sure not to enable the caps lock.

Running “htop” Command

Both the htop and top command display the same information when listing your Linux processes, but the former offers user-friendly features that are great for everyday process management.

First thing first, the htop command allows you to scroll vertically and horizontally. As such, you can see the complete list of your Linux processes along with their full command lines.

What’s more, the command allows you to use a mouse to select items, kill processes without inserting their PIDs, change the priority of multiple processes easily, and so on.

Unfortunately, most Linux distributions don’t have this command right out of the box, so you need to install it manually.

If you use Ubuntu, you can install htop by running the following command:

Once installed, type htop, and you’ll get a list of all your Linux processes. Just like the previous command, htop also has several keyboard shortcuts:

Keys Functions
F9 To kill a process.
F8 Increase the priority of a process.
F7 Decrease the priority of a process.
F6 Sort processes by any column.
F5 Display processes in a tree view.
F4 Filter the processes by name.
F3 Search for a process.
F2 Open htop setup.
F1 Display the help menu.

Conclusion

It is important to know how to list all running processes in your Linux operating system. The knowledge will be useful when you need to manage processes.

Let’s take a look once more at the three commands that you can use to list Linux processes:

  • ps command — outputs a static view of all processes.
  • top command — displays the real-time list of all running processes.
  • htop command — shows the real-time result and is equipped with user-friendly features.

Which command do you prefer? Share your thoughts in the comment section below!

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.

Источник

Linux List All Processes by Name, User, PID

Many times you need to list all processes in Linux to find out which processes are running, if a user is running any process, or if a specific process is running. Here’s how to list all processes by name, user, PID. You can use it to list all processes in Ubuntu, CentOS, Fedora, Redhat, and other Linux systems

How to List all Processes in Linux

Here are the steps to list all processes in Linux/Unix. There are various commands like ps, top, htop and pgrep to list all processes in Linux. We will use ps command to list processes.

Open terminal and run the following command to list all processes in Linux.

In the above command,
a = show processes for all users
u = display the process’s user/owner
x = also show processes not attached to a terminal

The above command will list all running processes.

List all processes by User

Here’s the command to list all processes by a specific user, say, john

In the above command,
-u : Show all processes by RUID
-U : Display all processes by EUID

Читайте также:  Как отключить введение пароля при включении компьютера windows 10

You can also use top or pgrep commands to list processes by user in Linux.

List Processes by Name

Here’s the command to list all processes by a specific name, say, firefox

In the above command, we pass the output of ps aux to grep command and search for string “firefox”.
You can also use pgrep command for this purpose. It searches the current running processes and lists PIDs of matching processes.

List Processes by PID

Here’s the command to list all processes by a specific PID, say, 1234

Hopefully, now you can easily list all processes in Linux/Unix.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!

Источник

Unix / Linux — Processes Management

In this chapter, we will discuss in detail about process management in Unix. When you execute a program on your Unix system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system.

Whenever you issue a command in Unix, it creates, or starts, a new process. When you tried out the ls command to list the directory contents, you started a process. A process, in simple terms, is an instance of a running program.

The operating system tracks processes through a five-digit ID number known as the pid or the process ID. Each process in the system has a unique pid.

Pids eventually repeat because all the possible numbers are used up and the next pid rolls or starts over. At any point of time, no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process.

Starting a Process

When you start a process (run a command), there are two ways you can run it −

  • Foreground Processes
  • Background Processes

Foreground Processes

By default, every process that you start runs in the foreground. It gets its input from the keyboard and sends its output to the screen.

You can see this happen with the ls command. If you wish to list all the files in your current directory, you can use the following command −

This would display all the files, the names of which start with ch and end with .doc

The process runs in the foreground, the output is directed to my screen, and if the ls command wants any input (which it does not), it waits for it from the keyboard.

While a program is running in the foreground and is time-consuming, no other commands can be run (start any other processes) because the prompt would not be available until the program finishes processing and comes out.

Background Processes

A background process runs without being connected to your keyboard. If the background process requires any keyboard input, it waits.

The advantage of running a process in the background is that you can run other commands; you do not have to wait until it completes to start another!

The simplest way to start a background process is to add an ampersand (&) at the end of the command.

This displays all those files the names of which start with ch and end with .doc

Here, if the ls command wants any input (which it does not), it goes into a stop state until we move it into the foreground and give it the data from the keyboard.

That first line contains information about the background process — the job number and the process ID. You need to know the job number to manipulate it between the background and the foreground.

Press the Enter key and you will see the following −

The first line tells you that the ls command background process finishes successfully. The second is a prompt for another command.

Listing Running Processes

It is easy to see your own processes by running the ps (process status) command as follows −

Читайте также:  Как поставить windows чувствительность

One of the most commonly used flags for ps is the -f ( f for full) option, which provides more information as shown in the following example −

Here is the description of all the fields displayed by ps -f command −

User ID that this process belongs to (the person running it)

Parent process ID (the ID of the process that started it)

CPU utilization of process

Process start time

Terminal type associated with the process

CPU time taken by the process

The command that started this process

There are other options which can be used along with ps command −

Sr.No. Column & Description
1

Shows information about all users

Shows information about processes without terminals

Shows additional information like -f option

Displays extended information

Stopping Processes

Ending a process can be done in several different ways. Often, from a console-based command, sending a CTRL + C keystroke (the default interrupt character) will exit the command. This works when the process is running in the foreground mode.

If a process is running in the background, you should get its Job ID using the ps command. After that, you can use the kill command to kill the process as follows −

Here, the kill command terminates the first_one process. If a process ignores a regular kill command, you can use kill -9 followed by the process ID as follows −

Parent and Child Processes

Each unix process has two ID numbers assigned to it: The Process ID (pid) and the Parent process ID (ppid). Each user process in the system has a parent process.

Most of the commands that you run have the shell as their parent. Check the ps -f example where this command listed both the process ID and the parent process ID.

Zombie and Orphan Processes

Normally, when a child process is killed, the parent process is updated via a SIGCHLD signal. Then the parent can do some other task or restart a new child as needed. However, sometimes the parent process is killed before its child is killed. In this case, the «parent of all processes,» the init process, becomes the new PPID (parent process ID). In some cases, these processes are called orphan processes.

When a process is killed, a ps listing may still show the process with a Z state. This is a zombie or defunct process. The process is dead and not being used. These processes are different from the orphan processes. They have completed execution but still find an entry in the process table.

Daemon Processes

Daemons are system-related background processes that often run with the permissions of root and services requests from other processes.

A daemon has no controlling terminal. It cannot open /dev/tty. If you do a «ps -ef» and look at the tty field, all daemons will have a ? for the tty.

To be precise, a daemon is a process that runs in the background, usually waiting for something to happen that it is capable of working with. For example, a printer daemon waiting for print commands.

If you have a program that calls for lengthy processing, then it’s worth to make it a daemon and run it in the background.

The top Command

The top command is a very useful tool for quickly showing processes sorted by various criteria.

It is an interactive diagnostic tool that updates frequently and shows information about physical and virtual memory, CPU usage, load averages, and your busy processes.

Here is the simple syntax to run top command and to see the statistics of CPU utilization by different processes −

Job ID Versus Process ID

Background and suspended processes are usually manipulated via job number (job ID). This number is different from the process ID and is used because it is shorter.

In addition, a job can consist of multiple processes running in a series or at the same time, in parallel. Using the job ID is easier than tracking individual processes.

Источник

Оцените статью
Sr.No. Option & Description
1