When analyzing process memory on Solaris, we need to distinguish between two key metrics:
- Resident Set Size (RSS): Physical memory currently in RAM
- Address Space: Total virtual memory allocated
The Solaris OS provides several built-in utilities for memory analysis:
# Basic process memory overview
ps -eo pid,user,rss,vsz,args | head -n 5
# Detailed mapping information
pmap -x PID
# Extended process statistics
prstat -s rss -n 5 -p PID
For scripting purposes, we can process pmap output to extract precise memory metrics:
#!/bin/ksh
pid=$1
total_mem=$(pmap -x $pid | tail -1 | awk '{print $3}')
resident_mem=$(pmap -x $pid | tail -1 | awk '{print $4}')
echo "PID $pid memory usage:"
echo "Total address space: ${total_mem}KB"
echo "Resident in RAM: ${resident_mem}KB"
For ongoing monitoring, prstat offers real-time RSS tracking:
# Monitor RSS changes every 5 seconds
prstat -r -p PID 5
For more control, we can directly access process memory information:
#!/bin/bash
pid=$1
rss_kb=$(awk '/Rss/ {sum += $2} END {print sum}' /proc/$pid/smaps)
total_kb=$(awk '/Size/ {sum += $2} END {print sum}' /proc/$pid/smaps)
printf "Process %d:\n" $pid
printf " Resident: %'d KB\n" $rss_kb
printf " Virtual: %'d KB\n" $total_kb
Method | Pros | Cons |
---|---|---|
pmap | Detailed mapping | Slower for large processes |
prstat | Real-time monitoring | Less detail |
/proc | Direct access | Solaris-specific |
When analyzing process memory consumption on Solaris, we need to distinguish between two key metrics:
- Virtual Size (VSZ): Total address space allocated to the process
- Resident Set Size (RSS): Portion actually residing in physical RAM
The most comprehensive approach combines several Solaris-specific commands:
# Basic process memory overview
prstat -a -p PID
# Detailed virtual memory map
pmap -x PID
# Alternative with resident memory breakdown
ps -eo pid,vsz,rss,args | grep PID
While you mentioned awk scripts feeling hacky, this refined approach handles edge cases:
pmap -x 1234 | awk '
BEGIN { total_kb = 0; rss_kb = 0 }
/^total/ { total_kb = $3; rss_kb = $4 }
END {
printf "Virtual: %.2fMB\n", total_kb/1024;
printf "Resident: %.2fMB\n", rss_kb/1024
}'
For ongoing monitoring, prstat
offers real-time insights with memory-specific columns:
prstat -a -s rss -n 5 -p 1234
When you need surgical precision, this DTrace script tracks memory allocation events:
#!/usr/sbin/dtrace -s
#pragma D option quiet
proc:::exec-success
{
self->exec = 1;
}
proc:::exec-failure
{
self->exec = 0;
}
vminfo:::anon_alloc
/self->exec/
{
@[execname] = sum(arg0);
}
END
{
printa("%s: %@d bytes allocated\n", @);
}
For production environments, consider these approaches:
- Parse
kstat
output for system-wide metrics - Use Solaris
libproc
API for custom tools - Configure SMF services with memory thresholds