PSTAT Interfaces

18
#define BURST ((size_t)10)
struct pst_status pst[BURST];
int i, count;
int idx = 0; /* index within the context */
/* loop until count == 0 */
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++) {
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;
}
if (count == -1) {
perror("pstat_getproc()");
}
}
/* Get a particular process' information. */
void main(void)
{
struct pst_status pst;
int target = (int)getppid();
if (pstat_getproc(&pst, sizeof(pst), (size_t)0, target) != -1) {
printf("Parent started at %s", ctime(&pst.pst_start));
} else {
perror("pstat_getproc");
}
}
4.16 pstat_getprocessor()
Synopsis:
int pstat_getprocessor(struct pst_processor *buf, size_t elemsize, size_t elemcount, int index);
Description:
This call returns information about processors in the system. Each structure returned
describes one processor on a multi-processor system. A total of one structure is returned for uni-
processor machines. For each instance data up to a maximum of elemsize bytes are returned in
the structs pst_processor pointed to by buf. The elemcount parameter specifies the number of
structs pst_processor that are available at buf. The index parameter specifies the starting index
within the context of processors.
Return Value:
This call returns –1 on failure or number of instances copied to buf on success.
Errors:
EINVAL is set if the user's size declaration isn't valid.
EINVAL is set if index < 0.