いくつかのシステム統計を出力するCプログラムがあります。
#include <sys/sysinfo.h>
#include <stdio.h>
int main() {
int days, hours, mins;
struct sysinfo sys_info;
if(sysinfo(&sys_info) != 0)
perror("sysinfo");
// Uptime
days = sys_info.uptime / 86400;
hours = (sys_info.uptime / 3600) - (days * 24);
mins = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);
printf("Uptime: %ddays, %dhours, %dminutes, %ldseconds\n",
days, hours, mins, sys_info.uptime % 60);
// Load Averages for 1,5 and 15 minutes
printf("Load Avgs: 1min(%ld) 5min(%ld) 15min(%ld)\n",
sys_info.loads[0], sys_info.loads[1], sys_info.loads[2]);
printf("Total Ram: %lluk\tFree: %lluk\n",
sys_info.totalram *(unsigned long long)sys_info.mem_unit / 1024,
sys_info.freeram *(unsigned long long)sys_info.mem_unit/ 1024);
// Number of processes currently running.
printf("Number of processes: %d\n", sys_info.procs);
return 0;
}
私の問題は、負荷平均値が/ proc/loadavgと異なることです
./a.out
Uptime: 1days, 4hours, 1minutes, 16seconds
Load Avgs: 1min(13248) 5min(14880) 15min(11840)
Total Ram: 2052956k Free: 188104k
Number of processes: 265
なんで?13248を印刷していますが、「top」または「cat / proc/loadavg」は0.24になります。何が問題ですか?