summaryrefslogtreecommitdiff
path: root/cmd_uptime.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-05-03 13:23:21 +0100
committerFreeArtMan <dos21h@gmail.com>2017-05-03 13:23:21 +0100
commit0a24537719de7cab1b4df46e7d6a22564f66ec6a (patch)
treed17f8215843fb4789bf8492ae633ec8cf4e00592 /cmd_uptime.c
parentc6f5689838de263b8129b7c612cde030617ce780 (diff)
downloadagni-0a24537719de7cab1b4df46e7d6a22564f66ec6a.tar.gz
agni-0a24537719de7cab1b4df46e7d6a22564f66ec6a.zip
Added new commands RUSAGE,LOADAVG
Diffstat (limited to 'cmd_uptime.c')
-rw-r--r--cmd_uptime.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/cmd_uptime.c b/cmd_uptime.c
index f745be0..285aec1 100644
--- a/cmd_uptime.c
+++ b/cmd_uptime.c
@@ -1,13 +1,34 @@
#include "cmd_uptime.h"
+#define PROCFS_PATH "/proc"
+#define PROCFS_UPTIME_PATH PROCFS_PATH "/uptime"
+
void *cmd_uptime(void *data)
{
char *param = (char *)data;
char *ret = NULL;
+ const int buf_size = 128;
+ char buf[buf_size+1];
+
printf("UPTIME\n");
-
- ret = alloc_new_str("UpTime is infinite\n");
+
+ FILE *f=NULL;
+ double d1,d2;
+ int i1,i2;
+
+ f = fopen(PROCFS_UPTIME_PATH,"r");
+ fscanf(f,"%lf %lf", &d1, &d2);
+ fclose(f);
+
+ printf("Readed %lf %lf\n", d1, d2);
+ i1 = d1;
+ i2 = d2;
+
+ printf("Days %d Hours %d Minutes %d\n",i1/(3600*24),i1/(3600)%24, (i1/60)%60);
+ snprintf(buf, buf_size,"Days %d Hours %d Minutes %d\n",i1/(3600*24),i1/(3600)%24, (i1/60)%60);
+
+ ret = alloc_new_str(buf);
return ret;
} \ No newline at end of file