Listing and Monitoring Running Processes
Effectively managing and monitoring running processes is a crucial aspect of system administration and troubleshooting in a Linux environment. Linux provides a variety of tools and commands that allow you to list, inspect, and monitor the status of running processes.
Listing Running Processes
The primary command used to list running processes in Linux is the ps
(process status) command. The ps
command can display various information about running processes, such as their process ID (PID), parent process ID (PPID), user, CPU and memory usage, and more.
## Example: List all running processes
$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Apr04 ? 00:00:05 /sbin/init
root 2 0 0 Apr04 ? 00:00:00 [kthreadd]
root 3 2 0 Apr04 ? 00:00:00 [rcu_gp]
root 4 2 0 Apr04 ? 00:00:00 [rcu_par_gp]
The ps
command can be customized with various options to display specific information or filter the output based on your needs.
Monitoring Running Processes
To monitor the status and resource utilization of running processes, you can use the top
command. The top
command provides a real-time, interactive view of the running processes, displaying information such as CPU and memory usage, process IDs, and more.
## Example: Monitor running processes using the `top` command
$ top
top - 10:24:37 up 30 days, 23:59, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 112 total, 1 running, 111 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.1 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 1992.0 total, 1388.9 free, 253.3 used, 349.8 buff/cache
MiB Swap: 2047.9 total, 2047.9 free, 0.0 used. 1484.1 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 4460 2776 1456 S 0.0 0.1 0:05.49 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
The top
command provides a real-time view of the system, allowing you to monitor and analyze the performance and resource utilization of running processes.