
{{ $('Map tags to IDs').item.json.title }}
How to Use top and ps to Monitor Processes
In Linux, monitoring system processes is crucial for effective system administration and troubleshooting. Two of the most commonly used commands for this purpose are top
and ps
. This tutorial will guide you on how to use both commands to monitor processes effectively.
1. Using the top Command
The top
command provides a real-time view of active processes. It displays system information such as CPU and memory usage, along with a list of processes and their resource utilization.
1.1. Starting top
To start top
, simply open your terminal and type:
top
The output will refresh every few seconds, providing you with up-to-date information.
1.2. Understanding the top Interface
When top
is running, the interface will show the following key sections:
- System Summary: Displays CPU usage, memory usage, and uptime.
- Process List: Lists all active processes, including their PID, user, CPU usage, memory usage, and command.
1.3. Interacting with top
While in the top interface, you can use various keyboard shortcuts to modify the display:
- h: Display help.
- q: Quit top.
- Shift + M: Sort processes by memory usage.
- Shift + P: Sort processes by CPU usage.
2. Using the ps Command
The ps
command provides a snapshot of current processes at the moment you execute it. Unlike top
, which continually updates, ps
returns a static list.
2.1. Basic Usage
To display a simple list of currently running processes, use:
ps aux
This command shows a detailed view of all processes, including:
- USER: The owner of the process.
- PID: The process ID.
- %CPU: CPU utilization.
- %MEM: Memory utilization.
- COMMAND: The command that started the process.
2.2. Filtering with ps
You can filter processes by using the grep
command. For example, to find all processes related to nginx
:
ps aux | grep nginx
3. Comparing top and ps
While top
provides a dynamic view of processes, ps
gives a snapshot. Depending on your needs:
- Use
top
for ongoing monitoring. - Use
ps
for a quick check or to search for specific processes.
4. Conclusion
By understanding how to use top
and ps
, you can effectively monitor and manage system processes in Linux. These commands are essential tools for system administrators and developers alike, enabling you to keep track of your system’s performance and resource usage.