PSTAT Interfaces
19
• EFAULT is set if buf points to an invalid address.
Example:
Get information about all processors, first obtaining number of processor context instances.
#include <sys/pstat.h>
#include <stdlib.h>
void main(void)
{
struct pst_dynamic psd;
struct pst_processor *psp;
int count;
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));
count = pstat_getprocessor(psp, sizeof(struct pst_processor),
nspu, 0);
if (count > 0) {
int i;
int total_execs = 0;
for (i = 0; i < count; i++) {
int execs = psp[i].psp_sysexec;
total_execs += execs;
printf("%d exec()s on processor #%d\n", execs,i);
}
printf("total execs for the system were %d\n",
total_execs);
}else {
perror("pstat_getprocessor");
}
} else {
perror("pstat_getdynamic");
}
}
4.17 pstat_getprocvm()
Synopsis:
int pstat_getprocvm(struct pst_vm_status *buf, size_t elemsize, size_t elemcount, int index);
Description:
This call provides information about process' address space. At most one instance
(process region) is returned for each call to pstat_getprocvm(). For each instance, data up to a
maximum of elemsize bytes are returned in the struct pst_vm_status pointed to by buf. The
elemcount parameter identifies the process for which address space information is to be returned.
An elemcount parameter of zero indicates that address space information for the currently
executing process should be returned. Information for a specific process (other than currently
executing one) may be obtained by setting elemcount to the PID of that process. The index
parameter specifies the relative index (beginning with 0) within the context of process regions
for the indicated process. For example, an index of 3 indicates the 4th process region within the