Browse Source

apéro de samedi midi en route...

master
tTh 3 years ago
parent
commit
2576b84d57
6 changed files with 55 additions and 5 deletions
  1. +1
    -0
      .gitignore
  2. +4
    -0
      Makefile
  3. +38
    -0
      essai.c
  4. +1
    -2
      fake-values.c
  5. +10
    -3
      funcs.c
  6. +1
    -0
      funcs.h

+ 1
- 0
.gitignore View File

@ -1,5 +1,6 @@
a.out
*.o
fake-values
essai

+ 4
- 0
Makefile View File

@ -4,6 +4,10 @@
CC = gcc
essai: essai.c funcs.o Makefile
gcc -Wall $< funcs.o -o $@
funcs.o: funcs.c funcs.h Makefile
gcc -Wall -c $<


+ 38
- 0
essai.c View File

@ -0,0 +1,38 @@
/*
* essai.c
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "funcs.h"
int verbosity;
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int opt, foo;
int type = 0;
double loads[3];
while ((opt = getopt(argc, argv, "vst:")) != -1) {
switch (opt) {
case 'v': verbosity++; break;
case 's': srand(getpid()); break;
case 't': type = atoi(optarg); break;
default: break;
}
}
foo = get_loadavg(loads);
if (foo) fprintf(stderr, "get loadavg -> %d\n", foo);
printf("%f %f %f %f\n", dtime(), loads[0], loads[1], loads[2]);
return 0;
}
/* --------------------------------------------------------------- */

+ 1
- 2
fake-values.c View File

@ -1,5 +1,5 @@
/*
* fake-values.c
* fake-values.c
*/
#include <stdio.h>
@ -30,7 +30,6 @@ if (verbosity > 1) {
fprintf(stderr, "fake values - %s %s\n", __DATE__, __TIME__);
}
printf("%f %d\n", dtime(), random1000(type));
return 0;


+ 10
- 3
funcs.c View File

@ -48,18 +48,25 @@ return (double)tv.tv_sec + (double)tv.tv_usec / 1e6;
/* --------------------------------------------------------------- */
double get_loadavg(int foo)
int get_loadavg(double *where)
{
FILE *fp;
double loads[3];
int foo;
if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
perror("read loadavg");
return -42.51;
return -1;
}
foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2);
if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
memcpy(where, loads, 3 * sizeof(double));
fclose(fp);
return -42.51;
return 0;
}
/* --------------------------------------------------------------- */

+ 1
- 0
funcs.h View File

@ -4,4 +4,5 @@
int random1000(int mode);
double dtime(void);
int get_loadavg(double *where);

Loading…
Cancel
Save