HP-UX Reference (11i v2 07/12) - 2 System Calls (vol 5)
p
pstat(2) pstat(2)
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);
}
else
perror("pstat_getdynamic");
}
else
perror("pstat_getdynamic");
}
/*
* Example 3: get information about all per-process -- 10 at a time
* done this way since current count of active processes unknown
*/
{
#define BURST ((size_t)10)
struct pst_status pst[BURST];
int i, count;
int idx = 0; /* index within the context */
/* loop until count == 0, will occur all have been returned */
while ((count=pstat_getproc(pst, sizeof(pst[0]),BURST,idx))>0) {
/* got count (max of BURST) this time. process them */
for (i = 0; i < count; i++) {
(void)printf("pid is %d, command is %s\n",
pst[i].pst_pid, pst[i].pst_ucomm);
}
/*
* now go back and do it again, using the next index after
* the current ’burst’
*/
idx = pst[count-1].pst_idx + 1;
}
HP-UX 11i Version 2: December 2007 Update − 12 − Hewlett-Packard Company 285