To find the load average in linux I use sys/sysinfo.h which include linux/kernel.h, where the following structure is defined:
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.. */
};
but I think it doesn't give true load.
output : 2552402, 3214049236, 134513148
What does this value mean?
We can find current load using the uptime
command:
$uptime
13:00:14 up 35 min, 2 users, load average: 1.07, 0.95, 0.80
I can't find any connection between above the two outputs.
I have searched on internet. This says that divide it by 2^16 (65536). and I have tried it too. (or do shift 1 by SI_LOAD_SHIFT i.e. 1 << SI_LOAD_SHIFT. because 65536 = 1 << 16)
I use computer which has four i3-2120 processor. Output of 'upitime' has connection with number of cpus. Wikipedia load_average
1 << SI_LOAD_SHIFT
? It works fine on my box (3.2.0-23-generic #36-Ubuntu SMP x86_64) – Soporific