HP-UX Reference (11i v3 07/02) - 2 System Calls (vol 5)

p
pstat(2) pstat(2)
[EOVERFLOW]
For pstat_getpathname()
, the elemcount parameter is not
1 greater than the length
of the path name to be returned.
[ESRCH] The process in question was not found or was exiting. For
pstat_getlv()
,
pstat_getmsg()
, pstat_getproc()
, pstat_getprocvm()
,
pstat_getpset()
, pstat_getsem()
,orpstat_getshm()
, elemcount was 0,
specifying the single-item short-cut, and no item matched the selection criteria in index.
For example,
PID for pstat_getproc()
.
EXAMPLES
All of these examples are compiled with the
_PSTAT64 flag. All examples have the following prolog. The
define of
_PSTAT64 is placed before the inclusion of the
<sys/pstat.h>
header so that it takes effect
in that file.
#ifndef _PSTAT64
#define _PSTAT64
#endif
#include <sys/pstat.h>
#include <sys/unistd.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
Example 1
Get global information from
pstat_getstatic()
.
main()
{
struct pst_static pst;
(void)memset(&pst,0,sizeof(struct pst_static));
if (pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == 1)
(void)printf("page size is %lld bytes\n", pst.page_size);
else
perror("pstat_getstatic");
}
Example 2
Get information about all processors, first obtaining number of processor context instances.
main()
{
struct pst_dynamic psd;
struct pst_processor *psp;
(void)memset(&psd,0,sizeof(struct pst_dynamic));
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));
(void)memset(psp,0,nspu*sizeof(struct pst_processor));
if (pstat_getprocessor(psp, sizeof(struct pst_processor), nspu,
0) != -1) {
int i;
unsigned long long total_execs = 0;
for (i = 0; i < nspu; i++) {
unsigned long long execs = psp[i].psp_sysexec;
total_execs += execs;
(void)printf("%llu exec()s on processor #%d\n",
execs, i);
}
HP-UX 11i Version 3: February 2007 17 Hewlett-Packard Company 307