Skip to content

Commit 25c83c8

Browse files
committed
Close file descriptor /proc/stat
1 parent 3050213 commit 25c83c8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

cputracker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int nproc = 0;
77
int main() {
88
if (get_nproc(&nproc) == -1)
99
exit(EXIT_FAILURE);
10-
10+
nproc++;
1111
print_stats();
1212
return 0;
1313
}

reader.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "reader.h"
22
#include "cputracker.h"
3+
#include <stdio.h>
34

45
int get_nproc(int *nproc) {
56
*nproc = sysconf(_SC_NPROCESSORS_ONLN);
@@ -18,7 +19,7 @@ struct proc_stat *get_proc_stats() {
1819
fgets(line, sizeof(line), file);
1920
// assert(strncmp(line, "cpu", 3) == 0);
2021
if (strncmp(line, "cpu", 3) != 0) {
21-
perror("Reading thread info failed\n");
22+
perror("Reading thread info failed");
2223
free(stats);
2324
return NULL;
2425
}
@@ -29,6 +30,7 @@ struct proc_stat *get_proc_stats() {
2930
&stats[thread].irq, &stats[thread].softirq, &stats[thread].steal,
3031
&stats[thread].guest, &stats[thread].guest_nice);
3132
}
33+
fclose(file);
3234
return stats;
3335
}
3436

0 commit comments

Comments
 (0)