PSTAT Interfaces
3
• For more information on how to use pstat interfaces please refer to the source code of
freeware application lsof at ftp://vic.cc.purdue.edu/pub/tools/unix/lsof
2. Overview
In the early days of UNIX, programmers and system administrators were required to write
their own tools to monitor and manage the system. In order to facilitate access to the internals of
the kernel implementation, UNIX provided the /dev/kmem and /dev/mem pseudo devices. This
was a reasonable thing to do in those days, as release-to-release binary compatibility was not an
issue. Modern UNIX systems now provide the application programmers with a rich set of
standard APIs. Writing applications that depend on kernel internals is no longer a recommended
practice. In fact, exposure to kernel internals creates serious binary compatibility problems for
user applications. The availability of many commercial applications for HP-UX makes the
release-to-release binary compatibility a very important feature.
Even today many system management and measurement tools read kernel data structures
through unsupported interfaces, such as /dev/kmem pseudo driver, to get information about open
files, resource usage, process activity, etc. Because kernel data structures change from release to
release, this access method is fragile, incurring a high maintenance cost. To insulate these
applications from the release-to-release variability in private kernel data structures, HP-UX
provides the pstat() system call and a set of wrappers. Pstat is a supported API that provides
many of the HP-UX system contexts. It provides a number of wrappers (pstat_get*) and
corresponding structures (struct pst_*) to get information from the kernel. These interfaces are
designed in such a way to allow future expansion of the interface, while preserving source and
binary compatibility for programs written using the pstat interfaces. Pstat interfaces are available
in both 64-bit and 32-bit versions. Replacing the /dev/kmem access with pstat wrappers will
eliminate the need to re-release these applications with each new HP-UX release.
3. Summary of Available Contexts
The general framework for pstat() interface is that the user programs call the libc
wrappers with required parameters. The wrappers then call the pstat() system call, passing the
required parameters. pstat() collects the required information and places it in the user’s buffer.
The pstat wrappers return information about various system contexts. The contents of the various
associated data structures are described in the Appendix. The following contexts of information
are returned by pstat wrappers: Static, Dynamic, Virtual Memory (VM), Inter Process
Communication (IPC), Stable Store, Crash Dumps, Processor, Disk, Swap Areas, Dump Areas,
Node (ccNUMA), Process, Light Weight Process (LWP), Process Region, Logical Volume
Manager Volume, Semaphore Set, Message Queue, Shared Memory, Open File, Open Socket,
Open Stream, and Dynamic Name Lookup Cache (DNLC). The following table summarizes the
various contexts.
Context Structure Routine Instances Short
Cut?
Static
Dynamic
VM
pst_static
pst_dynamic
pst_vminfo
pstat_getstatic()
pstat_getdynamic()
pstat_getvminfo
1
1
1