-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
44 lines (41 loc) · 1.02 KB
/
main.c
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
#include "main.h"
#define TIME_SLEEP 2
#define DURATION 20
void print_usage(){
printf("Usage: sys_monitor -C max_cpu -O ok_cpu -M max_memory \n");
}
int main(int argc, char *argv[])
{
int option = 0;
int MAX_CPU = -1;
int OK_CPU = -1;
int MAX_MEM = -1;
head_p proc_head;
head_b buf_head;
while ((option = getopt(argc, argv,"C:O:M:")) != -1) {
switch (option) {
case 'C' : MAX_CPU = atoi(optarg);
break;
case 'O' : OK_CPU = atoi(optarg);
break;
case 'M' : MAX_MEM = atoi(optarg);
break;
default: print_usage();
exit(EXIT_FAILURE);
}
}
if (MAX_CPU == -1 || MAX_MEM ==-1 || OK_CPU == -1) {
print_usage();
exit(EXIT_FAILURE);
}
//INITIALIZING HEADS OF LISTS
init_heads(&proc_head, &buf_head);
for (int i = 0; i < DURATION; i++) {
/* get_total_ram(); */
printf("\nITERACION %d:\n", i);
fill_list_buf(&buf_head, &proc_head, &MAX_CPU, &OK_CPU, &MAX_MEM);
sleep(TIME_SLEEP);
}
finish_processes(&buf_head, &proc_head);
exit(EXIT_SUCCESS);
}