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 <asm/param.h>
00057 #include <asm/page.h>
00058
00059 #include "process.h"
00060 #include "sysdep.h"
00061
00073 #define PAGE_TO_KBYTE_SHIFT PAGE_SHIFT-10
00074
00075 static long mem_kbyte_max;
00076
00077 int init_process_info_sysdep(void) {
00078
00079 struct stat buf;
00080
00081
00082
00083
00084 if ( stat("/proc/kcore", &buf) != 0 ) {
00085
00086 return FALSE;
00087
00088 }
00089
00090 num_cpus= sysconf(_SC_NPROCESSORS_CONF);
00091
00092 mem_kbyte_max = buf.st_size>>10;
00093
00094 return TRUE;
00095
00096 }
00097
00098
00099 int get_process_info_sysdep(ProcInfo_T p) {
00100
00101 char buf[4096];
00102 char* tmp;
00103 char stat_item_state;
00104 unsigned long stat_item_utime;
00105 unsigned long stat_item_stime;
00106 long stat_item_cutime;
00107 long stat_item_cstime;
00108 long stat_item_rss;
00109
00110 if (!read_proc_file(buf,4096, "stat", p->pid)) {
00111
00112 return FALSE;
00113
00114 }
00115
00116
00117
00118 tmp = strrchr(buf, ')') + 2;
00119
00120
00121
00122
00123 sscanf(tmp,"%c %*d %*d %*d %*d %*d %*u %*u"
00124 "%*u %*u %*u %lu %lu %ld %ld %*d %*d %*d "
00125 "%*d %*u %*u %ld %*u %*u %*u %*u %*u "
00126 "%*u %*u %*u %*u %*u %*u %*u %*u %*d %*d\n",
00127 &stat_item_state, &stat_item_utime, &stat_item_stime,
00128 &stat_item_cutime, &stat_item_cstime, &stat_item_rss);
00129
00130
00131
00132
00133 if ( PAGE_TO_KBYTE_SHIFT < 0 ) {
00134
00135 p->mem_kbyte= stat_item_rss >> abs(PAGE_TO_KBYTE_SHIFT);
00136
00137 } else {
00138
00139 p->mem_kbyte= stat_item_rss << abs(PAGE_TO_KBYTE_SHIFT);
00140
00141 }
00142
00143 p->mem_percent = (int) ((double) p->mem_kbyte * 1000.0 / mem_kbyte_max);
00144
00145
00146
00147
00148
00149 p->cputime_prev = p->cputime;
00150 p->cputime = ( stat_item_utime + stat_item_stime ) * 10 / HZ;
00151
00152 if ( include_children ) {
00153
00154 p->cputime += ( stat_item_cutime + stat_item_cstime ) * 10 / HZ;
00155
00156 }
00157
00158
00159
00160 if ( p->time_prev == 0.0 ) {
00161
00162 p->cputime_prev = p->cputime;
00163
00164 }
00165
00166
00167
00168 if ( stat_item_state == 'Z' ) {
00169
00170 p->status_flag |= PROCESS_ZOMBIE;
00171
00172 }
00173
00174 return TRUE;
00175
00176 }