HP-UX Reference (11i v3 07/02) - 2 System Calls (vol 5)
p
pstat_getlocality(2) pstat_getlocality(2)
main ( int argc, char **argv )
{
pid_t pid = (pid_t) 0;
if ( (argc == 2) || (argc > 3) ||
((argc == 3) && (strncmp(argv[1], "-p", 2))) ) {
usage(argc, argv);
}
if ( argc ==3){
pid = atoi(argv[2]);
if (pid < 0) {
/* note that pid 0 is "this process" */
usage(argc, argv);
}
}
/* Get the size of a page for later calculations */
pgsize = sysconf ( _SC_PAGE_SIZE );
sys_locinfo();
if ( argc ==3){
pid_locinfo ( pid );
}
return 0;
}
/*
* Display the system-wide memory usage per locality.
*/
void
sys_locinfo ( void )
{
int i; /* index within pstl[] */
int count; /* the actual number of pstl structures */
int idx = 0; /* index within the context of localities */
struct pst_locality pstl[BURST];
char total_str[STRSZ], free_str[STRSZ], used_str[STRSZ];
uint64_t total=0, free=0;
printf ( " --- System wide locality info: --- \n" );
printf ( "%6s%6s%7s%6s%10s%10s%10s\n",
"index", "ldom", "physid", "type",
"total", "free", "used" );
/* Get a maximum of BURST pst_locality structures */
count = pstat_getlocality ( pstl, sizeof(struct pst_locality),
BURST, idx );
while ( count>0){
for ( i=0 ; i<count ; i++ ) {
/* Keep running totals for later */
total += pstl[i].psl_total_pages;
free += pstl[i].psl_free_pages;
/* Convert integers into strings */
pages_to_str ( pstl[i].psl_total_pages, total_str );
pages_to_str ( pstl[i].psl_free_pages, free_str );
pages_to_str ( (pstl[i].psl_total_pages -
pstl[i].psl_free_pages), used_str );
320 Hewlett-Packard Company − 4 − HP-UX 11i Version 3: February 2007