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 <procfs.h>
00057
00058 #include "process.h"
00059 #include "sysdep.h"
00060
00073 int init_process_info_sysdep(void) {
00074
00075 num_cpus= sysconf( _SC_NPROCESSORS_ONLN);
00076
00077 return (getuid()==0);
00078
00079 }
00080
00081 double timestruc_to_tseconds(timestruc_t t) {
00082 return t.tv_sec * 10 + t.tv_nsec / 100000000.0;
00083 }
00084
00085 int get_process_info_sysdep(ProcInfo_T p) {
00086
00087 char buf[4096];
00088 psinfo_t * psinfo= (psinfo_t *)&buf;
00089 pstatus_t * pstatus= (pstatus_t *)&buf;
00090
00091 if (!read_proc_file(buf,4096, "psinfo", p->pid)) {
00092
00093 return FALSE;
00094
00095 }
00096
00097
00098
00099
00100 if ( psinfo->pr_nlwp == 0 ) {
00101
00102 p->status_flag = PROCESS_ZOMBIE;
00103
00104 }
00105
00106
00107 if ( p->status_flag != PROCESS_ZOMBIE ) {
00108
00109
00110
00111 p->mem_percent = psinfo->pr_pctmem * 1000 / 0x8000;
00112 p->mem_kbyte = psinfo->pr_rssize;
00113
00114 if (!read_proc_file(buf,4096, "status", p->pid)) {
00115
00116 return FALSE;
00117
00118 }
00119
00120 p->cputime_prev= p->cputime;
00121 p->cputime= ( timestruc_to_tseconds(pstatus->pr_utime) +
00122 timestruc_to_tseconds(pstatus->pr_stime) );
00123
00124 if( include_children ) {
00125
00126 p->cputime+= ( timestruc_to_tseconds(pstatus->pr_cutime) +
00127 timestruc_to_tseconds(pstatus->pr_cstime) );
00128
00129 }
00130
00131
00132 if ( p->time_prev == 0.0 ) {
00133
00134 p->cputime_prev= p->cputime;
00135
00136 }
00137
00138 } else {
00139
00140 p->cputime_prev= p->cputime = 0;
00141 p->mem_kbyte= 0;
00142 p->mem_percent= 0.0;
00143
00144 }
00145
00146 return TRUE;
00147
00148 }