File: get_load.c

package info (click to toggle)
wmavgload 0.6.1-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 112 kB
  • ctags: 66
  • sloc: ansic: 524; makefile: 36; sh: 35
file content (68 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifdef linux

#include <stdio.h>
#include <fcntl.h>

#else

#include <stdio.h>
#include <sys/param.h>
#include <rpcsvc/rstat.h>

#ifdef SVR4

#include <netdb.h>
#include <sys/systeminfo.h>

#ifndef FSCALE
#define FSCALE	(1 << 8)
#endif

char hostname[MAXHOSTNAMELEN];
struct statstime res;

#endif

#endif

void GetLoad(float *,float *,float *);

#ifdef linux
/* linux version */
void GetLoad(float *small,float *medium,float *large)
{ 
  char buffer[100];
  int fd, len;
  int total;
  char *p;

  fd = open("/proc/loadavg", O_RDONLY);
  len = read(fd, buffer, sizeof(buffer)-1);
  close(fd);
  buffer[len] = '\0';
  
  sscanf(buffer,"%f%f%f",small,medium,large);
  /* pas de verif ... */
}

#else
/* SVR4 */
void GetLoad(float *small,float *medium,float *large)
{
   /*
    * originally written by Matthieu Herrb - Mon Oct  5 1992
    * modified for optimization
    */

    if (rstat(hostname, &res) != 0) {
	perror("rstat");
	*small = *medium = *large = 0.0;
	return;
    }

    *small  = (float)res.avenrun[0]/FSCALE;
    *medium = (float)res.avenrun[1]/FSCALE;
    *large  = (float)res.avenrun[2]/FSCALE;
}

#endif