Listing Running Processes
To manage and monitor background processes effectively, it is essential to be able to list the running processes on your Linux system. There are several commands and tools available for this purpose, each with its own set of features and capabilities.
The ps
Command
The ps
(process status) command is one of the most commonly used tools for listing running processes. It provides a snapshot of the current processes and their associated information, such as process ID (PID), user, CPU and memory usage, and more.
Here's an example of using the ps
command to list all running processes:
$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 10:30 ? 00:00:05 /sbin/init
root 2 0 0 10:30 ? 00:00:00 [kthreadd]
root 3 2 0 10:30 ? 00:00:00 [rcu_gp]
root 4 2 0 10:30 ? 00:00:00 [rcu_par_gp]
root 6 2 0 10:30 ? 00:00:00 [kworker/0:0H-kblockd]
The ps -ef
command displays all running processes, including those in the background.
The top
Command
The top
command is another useful tool for monitoring running processes. It provides a real-time, dynamic view of the system's processes, with the ability to sort and filter the output based on various criteria.
When you run the top
command, you'll see a screen similar to the following:
top - 10:35:42 up 1 day, 23:05, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 125 total, 1 running, 124 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3880356 total, 3004220 free, 407540 used, 468596 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 3293972 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 172580 10340 7568 S 0.0 0.3 0:05.32 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
6 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kblockd
The top
command provides a real-time view of the system's processes, including information about CPU and memory usage, as well as the ability to sort and filter the output.
The htop
Command
htop
is an enhanced version of the top
command, providing a more user-friendly and interactive interface for monitoring running processes. It offers additional features, such as the ability to view process dependencies, kill processes, and customize the display.
To install htop
on your Ubuntu 22.04 system, run the following command:
sudo apt-get install htop
Once installed, you can launch htop
from the terminal:
$ htop
The htop
command provides a more visually appealing and intuitive way to manage and monitor running processes on your Linux system.
By using these tools, you can effectively list and monitor the running processes on your Linux system, which is essential for understanding system behavior, troubleshooting issues, and optimizing performance.