00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #ifdef HAVE_SYS_TYPES_H
00024 #include <sys/types.h>
00025 #endif
00026
00027 #include <unistd.h>
00028
00029 #ifdef HAVE_SYS_STAT_H
00030 #include <sys/stat.h>
00031 #endif
00032
00033 #ifdef HAVE_FCNTL_H
00034 #include <fcntl.h>
00035 #endif
00036
00037 #ifdef HAVE_STDLIB_H
00038 #include <stdlib.h>
00039 #endif
00040
00041 #ifdef TIME_WITH_SYS_TIME
00042 #include <time.h>
00043
00044 #ifdef HAVE_SYS_TIME_H
00045 #include <sys/time.h>
00046 #endif
00047 #else
00048 #include <time.h>
00049 #endif
00050
00051 #ifdef HAVE_STRING_H
00052 #include <string.h>
00053 #endif
00054
00055 #include <stdio.h>
00056 #include <strings.h>
00057 #include <sys/param.h>
00058 #define _RUSAGE_EXTENDED
00059 #include <sys/pstat.h>
00060 #include <nlist.h>
00061 #include <errno.h>
00062
00063 #include "process.h"
00064 #include "sysdep.h"
00065
00077 int init_process_info_sysdep(void) {
00078 struct pst_dynamic psd;
00079
00080 if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
00081
00082 num_cpus=psd.psd_proc_cnt;
00083
00084 } else {
00085
00086 return FALSE;
00087
00088 }
00089
00090 return TRUE;
00091 }
00092
00093
00094 int get_process_info_sysdep(ProcInfo_T p) {
00095
00096 struct pst_status ps;
00097
00098 if (pstat_getproc(&ps,sizeof(ps),(size_t)1,p->pid)==-1) {
00099
00100 return FALSE;
00101
00102 }
00103
00104
00105
00106
00107
00108 p->cputime_prev = p->cputime;
00109 p->cputime = ( ps.pst_utime + ps.pst_stime ) * 10 / HZ;
00110
00111 if ( include_children ) {
00112
00113 p->cputime += ( ps.pst_child_utime.pst_sec + ps.pst_child_stime.pst_sec ) * 10 / HZ;
00114
00115 }
00116
00117
00118
00119 if ( p->time_prev == 0.0 ) {
00120
00121 p->cputime_prev = p->cputime;
00122
00123 }
00124
00125
00126
00127 if ( ps.pst_stat || PS_ZOMBIE ) {
00128
00129 p->status_flag |= PROCESS_ZOMBIE;
00130
00131 }
00132
00133 return TRUE;
00134
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 int getloadavg (double *a, int na) {
00149
00150 struct pst_dynamic psd;
00151
00152 if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
00153
00154 switch (na) {
00155 case 3:
00156
00157 a[2]=psd.psd_avg_15_min;
00158
00159 case 2:
00160
00161 a[1]=psd.psd_avg_5_min;
00162
00163 case 1:
00164
00165 a[0]=psd.psd_avg_1_min;
00166
00167 }
00168
00169 } else {
00170
00171 return FALSE;
00172
00173 }
00174
00175 return TRUE;
00176 }