pstat.2 (2010 09)
p
pstat(2) pstat(2)
}
else
perror("pstat_getdynamic");
}
Example 4A
Get information about all processes, 10 at a time. We do it this way since the current count of active
processes is unknown.
main()
{
#define BURST ((size_t)10)
struct pst_status pst[BURST];
int i, count;
int idx = 0; /* pstat index within the Process pstat context */
/* loop until count == 0, will occur all have been returned */
(void)memset(pst,0,BURST*sizeof(struct pst_status));
while ((count=pstat_getproc(pst, sizeof(pst[0]),BURST,idx))>0) {
/* got count this time. process them */
for (i = 0; i < count; i++) {
(void)printf("pid is %lld, 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;
(void)memset(pst,0,BURST*sizeof(struct pst_status));
}
if (count == -1)
perror("pstat_getproc()");
#undef BURST
}
Example 4B
Get information about all processes, 10 at a time. We do it this way since the current count of active
processes is unknown. The program explicitly handles the possibility of [EOVERFLOW], as it is using
data from a field that may in principle overflow.
main()
{
#define BURST ((size_t)10)
struct pst_status pst[BURST];
int i, ret, count;
int idx = 0; /* pstat index within the Process pstat context */
do {
(void)memset(pst,0,BURST*sizeof(struct pst_status));
count = 0;
ret = pstat_getproc(pst, sizeof(pst[0]),BURST,idx);
if (ret > 0) {
/* normal case: got ret Process contexts to report */
count = ret;
}
else if ((ret == 0)) {
/* normal case: finished all Process contexts */
HP-UX 11i Version 3: September 2010 − 19 − Hewlett-Packard Company 19