How to use the command 'prstat' (with examples)
- Sunos
- December 17, 2024
The prstat
command is a powerful tool on UNIX-based systems, specifically useful in the Solaris operating environment, designed to report active process statistics. It provides system administrators with real-time monitoring of system resources in use by different processes. Comparable to the top
command in other UNIX systems, prstat
helps administrators quickly identify high resource usage processes, assess system performance, and optimize system efficiency.
Use case 1: Examine all processes and reports statistics sorted by CPU usage
Code:
prstat
Motivation:
Using prstat
without any additional arguments gives a comprehensive snapshot of all processes currently in operation. This specific command is essential for users wanting to quickly assess system load and demand on CPU resources. It is particularly beneficial in environments where CPU bottleneck issues need to be diagnosed, allowing users to see which processes are consuming the most CPU.
Explanation:
prstat
: The command executed without any flags defaults to sorting processes by CPU usage, providing an overview of active processes and their resource consumption.
Example Output:
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
12830 john 3896K 2672K sleep 59 0 0:00.04 0.0% vi/1
12810 mary 7952K 5488K cpu0 59 0 0:42.97 0.4% java/3
937 root 6088K 3920K run 49 0 0:16.10 5.1% httpd/1
TOTAL: 75 processes, 175 lwps, load averages: 0.25, 0.18, 0.15
Use case 2: Examine all processes and reports statistics sorted by memory usage
Code:
prstat -s rss
Motivation:
This command is tailored for scenarios where the primary concern is memory usage. System administrators can use this sort to detect memory hogs and troubleshoot potential memory leaks or swap issues on the system.
Explanation:
prstat
: Initiates the prstat report.-s rss
: Sorts the output by the ‘Resident Set Size’ (RSS), the non-swapped physical memory that a task has used. This detail helps to pinpoint processes consuming excessive memory.
Example Output:
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
820 admin 200M 100M sleep 59 0 0:04.33 0.2% mysql/5
1300 system 550M 200M sleep 59 0 0:01.45 0.3% oracle/20
TOTAL: 80 processes, 200 lwps, load averages: 0.35, 0.20, 0.18
Use case 3: Report total usage summary for each user
Code:
prstat -t
Motivation:
This command provides a user-centric summary of the system’s resource usage. It’s particularly useful in shared environments where processes are associated with different users, allowing administrators to evaluate multi-user resource distribution efficiently.
Explanation:
prstat
: Initiates the prstat utility.-t
: Summarizes the aggregate CPU and memory usage for all processes owned by each user, helping to quickly evaluate which users are the largest resource consumers.
Example Output:
USERNAME NPROC SIZE RSS MEMORY TIME CPU
admin 12 400M 260M 10% 1:30:12 14.9%
guest 5 180M 120M 4% 0:12:02 1.8%
TOTAL: 20 users spanning 85 processes, 270 lwps, load averages: 0.45, 0.25, 0.20
Use case 4: Report microstate process accounting information
Code:
prstat -m
Motivation:
The microstate accounting feature provides detailed information about the time processes spend in various states, including system CPU time, user CPU time, sleep, and wait states. This detailed insight is crucial for thorough system performance analysis and debugging complex performance issues.
Explanation:
prstat
: Starts the prstat utility.-m
: Activates microstate accounting, which enhances the output with additional columns related to microstates, providing deeper insights into process states.
Example Output:
PID USERNAME SIZE RSS STATE PRI NICE SYS USER SLP WAIT LAT PROCESS/NLWP
1010 service 128M 98M sleep 59 0 0:08.13 0:01:32 1:10.10 0:00.01 0.382 coolapp/4
533 root 256M 156M run 59 0 0:03.24 0:02:06 0:14.02 0:00.01 0.217 apache2/10
TOTAL: 60 processes, 150 lwps, load averages: 0.50, 0.30, 0.25
Use case 5: Print out a list of top 5 CPU using processes every second
Code:
prstat -c -n 5 -s cpu 1
Motivation:
In fast-paced troubleshooting scenarios, you may need to closely monitor the top CPU-consuming processes with frequent updates. This command is ideal for such purposes, helping users quickly pinpoint problematic processes without sifting through redundant data.
Explanation:
prstat
: Launches the prstat utility.-c
: Displays a continuous display of the output until stopped manually, providing a real-time process monitoring experience.-n 5
: Limits the display to the top 5 processes, reducing clutter and focusing analysis on the most critical data.-s cpu
: Sorts processes by CPU usage, highlighting those that are burdening the CPU.1
: Refreshes the data every second, ensuring up-to-the-second process information is displayed.
Example Output:
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
15010 developer 150M 112M run 59 0 2:08.42 15.8% buildprocess/10
10232 dbadmin 200M 175M run 59 0 1:32.19 12.4% postgresql/5
TOTAL: 85 processes, 270 lwps, load averages: 0.60, 0.40, 0.30
Conclusion:
The prstat
command is a versatile and indispensable tool for system administrators in the Solaris operating environment. From identifying CPU and memory hogs to providing a detailed tally of user resource consumption and microstate details, prstat
can be configured to present critical system information tailored to user needs. By familiarizing oneself with its various options and output formats, system administrators can efficiently monitor, diagnose, and manage the health and performance of their systems.