Current memory usage of process at runtime on Solaris
Is there a way to determine (or even estimate) the memory usage of a process on Solaris from within the running process? I need to write a function to do some memory clean-up to keep my process below a certain threshold when it grows too large.
It seems like Solaris does not support getrusage or any way of querying the system for the current RSS/VSZ (memory usage) like Linux/Windows.
One way to get the information is to read the data from the /proc
filesystem. You can get the information you want from /proc/self/psinfo
, /proc/self/map
, or /proc/self/xmap
. See man -s 4 proc
.
The /proc/self/psinfo
file contains a struct psinfo
/ psinfo_t
as described via procfs.h
. The structure contains the size_t pr_size;
which contains "the size of the process image in kBytes", and size_t pr_rssize;
which contains "resident set size in kBytes".
The /proc/self/map
and /proc/self/xmap
files contain arrays of struct prmap
/ prmap_t
structures and struct prxmap
/ prxmap_t
structures, respecitively. Both structures contain a size_t pr_size;
field defined as "size of mapping in bytes".
Be careful reading /proc
- make sure you understand if the data you're trying to read is stored for a 32- or 64-bit process. Offhand, I think everything in Solaris /proc
is now 64-bit.