If you are new to Linux, it is essential that you know how to determine the processes that consume most of your resources. You can manage them accordingly if you know where to begin.
Processes in Linux
Processes are running programs launched via opening an application or executing a command via the command-line terminal. Note that an application can run many processes for various tasks.
Each process in Linux has a unique process identification number (PID) assigned. The system will only reuse the old PIDs whenever there are no more possible combinations left.
Managing Linux processes
Processes in Linux can be initiated as a background or a foreground process. Commands running in the shell will start as foreground processes. When the process occupies the shell, you can only execute other commands when it is done.
At some point, processes can use a lot of resources that need to be terminated. You may also change the priority level of a process to allocate more resources to it. That is why listing the running processes on Linux is essential to manage them effectively.
List Linux running processes
A number of commands can be used to list the running processes, which include htop, ps, and top.
- The PS command
The process status or ps command creates a snapshot of all running processes. Thus, the results are all static unlike the Windows task manager. This command will return a list of running processes if no other argument or options are added.
There are 4 crucial columns, which include the PID, TTY or terminal name, TIME or running time, and CMD or name of the command that launches the process.
For a more in-depth information about the running processes, you may use the ‘ps aux’ command instead.
- a – this will show all the running processes of all system users
- u – provides more information such as the CPU and memory usage percentage, the process state code, and owner of the processes.
- x – this option lists all processes not executed from the terminal. Daemons are examples of this process running in the background once the system is booted up.
The processes can be displayed in a hierarchical view if you use the ‘ps -axjf’ command. The shell will put the child processes in this format under the individual parent processes.
- ps -u [username] – this will list all running processes of a certain user
- ps -e or ps -A – displays the active Linux processes in generic UNIX format
- ps -T – this prints the active processes executed from the terminal
- ps -C process_name – this will filter the list according to the process name. Also, this will show all child processes of a particular process.
- The top command
This command is able to provide information about the resource-hungry processes. This will also sort the list by CPU usage, putting the resources with the most consumption on top of the list.
The output of the top command is also updated periodically unlike the ps command. That said, you can see real-time updates for the running time and CPU usage.
- The htop command
Both top and htop commands display the same information when listing Linux processes. However, htop offers user-friendly features that are excellent for daily process management.
This command also allows you to scroll horizontally and vertically. Thus, you will be able to see the complete list of the processes along with their full command lines.
Overall, listing the running processes in your Linux OS is important because it can make you manage them effectively.