Observation Tools
Linux Processing Text Tools
ps - Displaying Process Information:
ps displays information about active processes.
Common options:
- aux: Displays all processes for all users, including detailed information.
- -e: Shows every process.
- -f: Provides a full listing format.
- grep
<process_name>
Filter the output to show only processes matching a specific name.
-
Basic Example:
# Shows all processes running on the system with detailed information
ps aux | grep mysql
# Displays processes in a tree-like format, showing parent-child relationships. Useful for understanding process hierarchies
ps -ef
# Shows only processes with the specified command name
ps -C mysql
# Displays processes owned by a specific user
ps -u
top - Dynamic Real-time Process Monitoring:
top provides a dynamic, real-time view of running processes, including CPU usage, memory consumption, and other metrics.
Interactive commands (while top is running):
-
M: Sort by memory usage.
-
P: Sort by CPU usage.
-
h: Display help.
-
q: Quit top.
The top part of the top display shows system-wide information (CPU usage, memory usage, load average), and the bottom part lists the processes.
iostat - Input/Output Statistics:
iostat monitors system input/output device loading by observing the time the devices are active in relation to their average transfer rates
Common options:
<interval>
<count>
: Specifies the reporting interval in seconds and the number of reports.
-
Basic Example:
# This command displays I/O statistics every second for 5 iterations.
iostat 1 5
# Shows extended statistics, including merge requests and average queue lengths. Useful for more in-depth I/O analysis.
iostat -x
# Shows statistics for a specific device (e.g., iostat -p sda for the first SATA drive)
iostat -p <device>
# Displays statistics every 2 seconds continuously.
iostat 2:
vmstat - Virtual Memory Statistics:
vmstat reports information about processes, memory, paging, block I/O, traps, and CPU activity.
Common options:
<interval>
<count>
: Similar to iostat, specifies the reporting interval and count.
-
Basic Example:
# Displays virtual memory statistics every 2 seconds for 10 iterations
vmstat 2 10
# Displays statistics every second continuously.
vmstat 1
# Includes disk statistics. Useful for monitoring disk I/O activity.
vmstat -d
# Displays a summary of various system statistics.
vmstat -s
free - Displaying Memory Usage:
free displays the amount of free and used memory in the system.
Common options: -h: Displays output in human-readable format (e.g., KB, MB, GB).
-
Basic Example:
# Displays memory information in megabytes
free -m
# Displays memory information in gigabytes.
free -g
# Displays a total line at the bottom.
free -t
df - Displaying Disk Space Usage:
df displays disk space usage for file systems.
Common options:
- -h: Human-readable format.
- -T: Includes file system type.
-
Basic Example:
# Displays disk usage
df -h
# Shows inode usage. Inodes are data structures that store information about files. Running out of inodes can prevent file creation even if there's free disk space.
df -i:
# Shows disk usage for the specific directory or mount point.
df -h /path/to/directory:
uptime - Displaying System Uptime and Load Average:
uptime shows how long the system has been running and the average number of processes that have been waiting to run in the last 1, 5, and 15 minutes (load average).
-
Basic Example:
# Displays uptime
uptime
nproc - Displaying the Number of Available Processors:
df displays disk space usage for file systems.
Common options:
- -h: Human-readable format.
- -T: Includes file system type.
-
Basic Example:
# Check total processors
nproc