76 |
|
#endif |
77 |
|
#if defined(LINUX) || defined(CYGWIN) |
78 |
|
FILE *f; |
79 |
+ |
int proc_stat_cpu; |
80 |
|
#endif |
81 |
|
#ifdef ALLBSD |
82 |
|
#if defined(NETBSD) || defined(OPENBSD) |
141 |
|
sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/stat"); |
142 |
|
return NULL; |
143 |
|
} |
144 |
+ |
|
145 |
|
/* The very first line should be cpu */ |
146 |
< |
if((fscanf(f, "cpu %lld %lld %lld %lld", \ |
146 |
> |
proc_stat_cpu = fscanf(f, "cpu %lld %lld %lld %lld %lld", \ |
147 |
|
&cpu_now.user, \ |
148 |
|
&cpu_now.nice, \ |
149 |
|
&cpu_now.kernel, \ |
150 |
< |
&cpu_now.idle)) != 4){ |
150 |
> |
&cpu_now.idle, \ |
151 |
> |
&cpu_now.iowait); |
152 |
> |
|
153 |
> |
fclose(f); |
154 |
> |
|
155 |
> |
if (proc_stat_cpu < 4 || proc_stat_cpu > 5) { |
156 |
|
sg_set_error(SG_ERROR_PARSE, "cpu"); |
150 |
– |
fclose(f); |
157 |
|
return NULL; |
158 |
|
} |
159 |
|
|
160 |
< |
fclose(f); |
160 |
> |
/* older linux doesn't give iowait */ |
161 |
> |
if (proc_stat_cpu == 4) { |
162 |
> |
cpu_now.iowait = 0; |
163 |
> |
} |
164 |
|
|
165 |
|
cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle; |
166 |
|
#endif |