summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/procfs.c24
-rw-r--r--src/procfs.h2
2 files changed, 23 insertions, 3 deletions
diff --git a/src/procfs.c b/src/procfs.c
index 346a151..95478a2 100644
--- a/src/procfs.c
+++ b/src/procfs.c
@@ -21,6 +21,7 @@
#include "err-check.h"
#define LOADAVG_FILEPATH "/proc/loadavg"
+#define UPTIME_FILEPATH "/proc/uptime"
int procfs_read_system_load_average(struct procfs_load_average_info *info)
{
@@ -74,9 +75,28 @@ int procfs_read_process_cpu_usage(int pid, struct procfs_process_cpu_usage_info
return -1;
}
-int procfs_read_uptime(int *uptime)
+int procfs_read_uptime(unsigned long *uptime)
{
- return -1;
+ ON_NULL_RETURN_VAL(uptime, -1);
+
+ double duptime;
+
+ FILE *uptime_fp = fopen(UPTIME_FILEPATH, "r");
+ if (!uptime_fp) {
+ ERR("failed to open " UPTIME_FILEPATH);
+ return -1;
+ }
+
+ if (fscanf(uptime_fp, "%lf ", &duptime) != 1) {
+ ERR("failed to read " UPTIME_FILEPATH);
+ fclose(uptime_fp);
+ return -1;
+ }
+
+ fclose(uptime_fp);
+ *uptime = (unsigned long)duptime;
+
+ return 0;
}
int procfs_read_cpu_count(int *cpu_count)
diff --git a/src/procfs.h b/src/procfs.h
index 734bd23..acedc9f 100644
--- a/src/procfs.h
+++ b/src/procfs.h
@@ -137,7 +137,7 @@ int procfs_read_process_cpu_usage(int pid, struct procfs_process_cpu_usage_info
* @param[out] uptime Number of seconds after boot
* @return: 0 on success, other value on error
*/
-int procfs_read_uptime(int *uptime);
+int procfs_read_uptime(unsigned long *uptime);
/**
* @brief Parses information from /sys/devices/system/cpu/possible