apéro de samedi midi en route...
This commit is contained in:
parent
44befe2867
commit
2576b84d57
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
a.out
|
||||
*.o
|
||||
fake-values
|
||||
essai
|
||||
|
||||
|
||||
|
4
Makefile
4
Makefile
@ -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
essai.c
Normal file
38
essai.c
Normal 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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- */
|
@ -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;
|
||||
|
13
funcs.c
13
funcs.c
@ -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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user