Monitoring and Analyzing Processes
Effectively monitoring and analyzing processes is essential for understanding system performance, identifying bottlenecks, and troubleshooting issues. Linux provides various tools and commands to help you achieve this.
Viewing Running Processes
The ps
(process status) command is the primary tool for viewing information about running processes. You can use it to list all running processes, filter by specific criteria, and display detailed process information.
$ 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]
Viewing Process Details
To get more detailed information about a specific process, you can use the pstree
command to view the process hierarchy, or the top
command to monitor real-time process activity and resource usage.
$ pstree -p
init(1)─┬─accounts-daemon(596)
├─agetty(687)
├─atd(623)
├─cron(622)
├─dbus-daemon(595)
├─irqbalance(607)
├─networkd-dispatcher(608)
├─rsyslogd(614)
├─snapd(619)
├─systemd-journal(571)
├─systemd-logind(604)
├─systemd-networkd(602)
├─systemd-resolved(603)
├─systemd-timesyncd(601)
└─ubuntu-advantage-tools(624)
Analyzing Process Resource Usage
To understand how processes are utilizing system resources, such as CPU, memory, and disk I/O, you can use the top
or htop
commands. These tools provide real-time monitoring of process performance and resource consumption.
$ top
top - 10:30:00 up 1 day, 5:00, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 123 total, 1 running, 122 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.1 sy, 0.0 ni, 99.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 3892.0 total, 3073.5 free, 323.5 used, 495.0 buff/cache
MiB Swap: 2047.9 total, 2047.9 free, 0.0 used. 3316.8 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 4548 2408 1400 S 0.0 0.1 0:05.11 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
This information can help you identify processes that are consuming excessive resources and take appropriate actions to optimize system performance.