HP-UX Reference (11i v1 05/09) - 2 System Calls (vol 5)

p
pstat(2) pstat(2)
[ENOSYS] The requested pstat function is not implemented or not configured in the system.
BACKWARD COMPATIBILITY
The specific calling convention of passing the expected data structure size is used in order to allow for
future expansion of the interface, while preserving backwards source and object compatibility for programs
written using the pstat interfaces. Three rules are followed to allow existing applications to continue to
execute from release to release of the operating system.
New data for a context are added to the end of that context’s data structure.
Old, obsolete data members are
NOT deleted from the data structure.
The operating system honors the
elemsize parameter of the call and only returns the first
elemsize bytes of the context data, even if the actual data structure has since been enlarged.
In this way, an application which passes its compile-time size of the context’s data structure (for example,
sizeof(struct pst_processor
) for the per-process context) as the elemsize parameter will
continue to execute on future operating system releases without recompilation, even those that have larger
context data structures. If the program is recompiled, it will also continue to execute on that and future
releases. Note that the reverse is not true: a program using the
pstat interfaces compiled on, say,
HP-UX
release 10.0 will not work on HP-UX release 9.0.
The code examples, below, demonstrate the calling conventions described above.
EXAMPLES
#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/unistd.h>
/*
* Example 1: get static global information
*/
{
struct pst_static pst;
if (pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) != -1)
(void)printf("page size is %d bytes\n", pst.page_size);
else
perror("pstat_getstatic");
}
/*
* Example 2: get information about all processors, first obtaining
* number of processor context instances
*/
{
struct pst_dynamic psd;
struct pst_processor *psp;
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1) {
size_t nspu = psd.psd_proc_cnt;
psp = (struct pst_processor *)
malloc(nspu * sizeof(struct pst_processor));
if (pstat_getprocessor(psp, sizeof(struct pst_processor), nspu,
0) != -1) {
int i;
int total_execs = 0;
for (i = 0; i < nspu; i++) {
int execs = psp[i].psp_sysexec;
total_execs += execs;
(void)printf("%d exec()s on processor #%d\n",
execs, i);
}
(void)printf("total execs for the system were %d\n",
total_execs);
HP-UX 11i Version 1: September 2005 10 Hewlett-Packard Company Section 2247