Skip to content

Instantly share code, notes, and snippets.

@kinichiro
Created August 14, 2014 04:30
Show Gist options
  • Save kinichiro/12b8de30bde3ecc62150 to your computer and use it in GitHub Desktop.
Save kinichiro/12b8de30bde3ecc62150 to your computer and use it in GitHub Desktop.
sample code for pstat_getproc()
/* test_pstat_getproc.c */
#include <stdio.h>
#include <unistd.h>
#include <sys/pstat.h>
int main() {
struct pst_status buf;
if(pstat_getproc(&buf, sizeof(buf), 0, getpid()) != 1) {
perror("pstat_getproc()");
return -1;
}
printf("++++++++++----------++++++++++----------++++++++++----------\n");
printf("# real pages used for data = %d\n", buf.pst_dsize);
printf("# real pages used for text = %d\n", buf.pst_tsize);
printf("# real pages used for stack = %d\n", buf.pst_ssize);
printf("address of process (in memory) = 0x%8.8x\n", buf.pst_addr);
printf("processor utilization for scheduling = %d\n", buf.pst_cpu);
printf("user time spent executing (in seconds) = %d\n", buf.pst_utime);
printf("system time spent executing (in seconds) = %d\n", buf.pst_stime);
printf("%cpu for this process(smoothed) = %f\n", buf.pst_pctcpu);
printf("clock ticks left in process RR timeslice = %d\n", buf.pst_ticksleft);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment