Process Monitoring and Filtering
Effective process monitoring and filtering are essential for understanding system behavior, identifying performance bottlenecks, and troubleshooting issues. Linux provides a variety of tools and commands to help you effectively manage and analyze running processes.
Listing Processes with the ps
Command
The ps
(process status) command is a fundamental tool for listing and monitoring running processes. It allows you to view detailed information about processes, such as their process ID, user, CPU and memory usage, and the command being executed.
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 18236 4448 ? Ss Jan01 0:01 /sbin/init splash
root 2 0.0 0.0 0 0 ? S Jan01 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< Jan01 0:00 [rcu_gp]
...
The ps
command can be customized with various options to filter and sort the output based on your specific needs.
Filtering Processes
To filter the list of running processes, you can use the ps
command with additional options or combine it with other tools like grep
. This allows you to focus on specific processes based on criteria such as process name, user, CPU/memory usage, and more.
$ ps aux | grep nginx
www-data 1234 0.0 0.2 46420 2364 ? Ss Jan01 0:02 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 1235 0.0 0.1 46888 1496 ? S Jan01 0:00 nginx: worker process
This example filters the process list to show only the NGINX web server processes.
Monitoring Process Resource Usage
To monitor the resource usage of running processes, you can use the top
command, which provides a real-time, interactive view of system activity. The top
command displays information about the processes, including their CPU and memory utilization, as well as other system-level metrics.
$ top
top - 10:30:02 up 1 day, 3:29, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 262 total, 1 running, 261 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 : 3841864 total, 1229628 free, 589340 used, 2022896 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 2796288 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 18236 4448 2908 S 0.0 0.1 0:01.37 /sbin/init splash
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [kthreadd]
3 root 20 0 0 0 0 I 0.0 0.0 0:00.00 [rcu_gp]
...
The top
command provides a wealth of information about running processes, allowing you to identify and analyze resource-intensive processes.