Master Linux System Monitoring: Essential Commands & Smem Tips
This guide walks you through Linux command‑line shortcuts, the five key system‑operation metrics, and powerful tools like smem, ps, and sort to efficiently monitor CPU, memory, processes, disks, and network while also handling zombie processes.
Command Line Learning Shortcut
Linux commands are powerful for everything from simple file operations to complex multimedia processing, but beginners often know commands without understanding how to troubleshoot system failures. The key is to combine theoretical knowledge with practical system operations.
5 Major System Operation States
For operations, checking system status is fundamental. To monitor CPU, memory, processes, disks, and network you need commands such as ls, ps, free, top, uptime, ifconfig, su / sudo, dmesg, iostat, vmstat, sar, htop, iotop, smem. This article highlights a few especially efficient commands.
Typical Linux Commands
Because Linux uses virtual memory, calculating a process's actual physical memory usage is non‑trivial. smem is a command‑line tool that provides detailed memory‑usage reports.
Memory Status Detection Tool
To install smem, enable the EPEL repository and install the required packages:
yum install epel-release
yum install smem python-matplotlib python-tkRun smem with options to display per‑process memory usage:
The -k flag shows memory units, -s sorts, and uss sorts by unshared set size, producing a clear list of memory consumption. smem can also show memory usage as a percentage with the -p option, and per‑user usage with -u. Example commands:
smem -P nginx
smem -k -P nginxThus smem makes it easy to obtain each process's memory footprint, an essential tool for operations.
CPU/Memory Intensive Processes
To list the top 10 CPU‑consuming processes, combine ps and sort:
ps aux | head -1
ps aux | sort -rn -k3 | head -10The first line prints the header. The pipeline sorts all processes by the third column (%CPU) in descending order and shows the top ten.
Removing Zombie Processes
A zombie process remains after its child exits but before the parent reaps it. Detect zombies with: ps -e -o stat,ppid,pid,cmd | egrep '^[Zz]' To kill all zombies in bulk:
ps -e -o stat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}' | xargs kill -9This pipeline uses grep to filter zombie entries, awk to extract the parent PID, and xargs to pass those PIDs to kill -9.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
