File: getloadavg.c

package info (click to toggle)
bsdgames 2.1-3hamm1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 8,368 kB
  • ctags: 4,860
  • sloc: ansic: 59,005; makefile: 1,058; sh: 511; yacc: 327; lex: 79; sed: 13; csh: 5
file content (26 lines) | stat: -rw-r--r-- 574 bytes parent folder | download | duplicates (2)
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
/* getloadavg.c - bsd-games implementation of getloadavg */

#include <stdio.h>
#include <stdlib.h>

int
getloadavg(double loadavg[], int nelem)
{
  double load_averages[3];
  FILE *fp;
  int count;
  int i;
  int nc;
  fp = fopen("/proc/loadavg", "r");
  if (fp == NULL)
    return -1;
  count = fscanf(fp, "%lf%lf%lf", &(load_averages[0]), &(load_averages[1]),
		 &(load_averages[2]));
  fclose(fp);
  if ((count == EOF) || (count == 0))
    return -1;
  nc = ((nelem < count) ? nelem : count);
  for (i = 0; i < nc; i++)
    loadavg[i] = load_averages[i];
  return nc;
}