2012-09-06 51 views
3

返回負荷要找到在linux平均負載我用sys/sysinfo.h其中包含linux/kernel.h當,在下面的結構定義:能不能理解SYSINFO

struct sysinfo { 
long uptime;   /* Seconds since boot */ 
unsigned long loads[3];  /* 1, 5, and 15 minute load averages */ 
unsigned long totalram;  /* Total usable main memory size */ 
unsigned long freeram;  /* Available memory size */ 
unsigned long sharedram; /* Amount of shared memory */ 
unsigned long bufferram; /* Memory used by buffers */ 
unsigned long totalswap; /* Total swap space size */ 
unsigned long freeswap;  /* swap space still available */ 
unsigned short procs;  /* Number of current processes */ 
unsigned short pad;  /* explicit padding for m68k */ 
unsigned long totalhigh; /* Total high memory size */ 
unsigned long freehigh;  /* Available high memory size */ 
unsigned int mem_unit;  /* Memory unit size in bytes */ 
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ 
}; 

但我認爲這不給真正的負擔。

輸出: 2552402,3214049236,134513148

是什麼值呢?

我們可以使用uptime命令找到當前負載:

$uptime 
13:00:14 up 35 min, 2 users, load average: 1.07, 0.95, 0.80 

我不能找到兩個輸出以上之間的任何連接。


我在網上搜索過。 This表示將它除以2^16(65536)。我也試過了。 (或不通過SI_LOAD_SHIFT移位1即1 < < SI_LOAD_SHIFT。因爲65536 = 1 < < 16)

我使用其具有四個睿i3-2120處理器計算機。 'upitime'的輸出與cpus的數量有關。 Wikipedia load_average

+0

你在運行什麼內核?你通過'1 << SI_LOAD_SHIFT'獲得了什麼結果?它工作正常我的盒子(3.2.0-23 - 通用#36 - Ubuntu的SMP x86_64) – aland

+0

可能重複的[sysinfo系統調用返回錯誤的負載平均值在Linux](http://stackoverflow.com/questions/4993158/ sysinfo-system-call-returns-wrong-load-average-values-on-linux) – tripleee

+0

內核版本爲Linux 3.0.0-21-generic#35〜lucid1-Ubuntu SMP。 如果我用(1 << SI_LOAD_SHIFT)除負載,我得到的輸出爲 113,49088,2052. – Ravi

回答

1

負載平均值以定點算術表示。相關常數見here。我們看到最後的FSHIFT位用來表示小數部分。要獲得負載平均值,您可以始終這樣做,如/proc/loadavg

1

我得到了解決方案。

我忘了打電話sysinfo(&sysinfo_obj)功能。