summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordianshi <dianshi@main.lv>2020-06-29 22:30:24 +0100
committerdianshi <dianshi@main.lv>2020-06-29 22:30:24 +0100
commitea30aa946ef4b441d05c003bd74a65b5a67de3c5 (patch)
tree983fe1d905dfc6432870610a3aaa6e0864d80ef4
parent81cece0dc62e1ba9d162ab12ae361b870d74568a (diff)
downloadosystem-ea30aa946ef4b441d05c003bd74a65b5a67de3c5.tar.gz
osystem-ea30aa946ef4b441d05c003bd74a65b5a67de3c5.zip
Add ouptime
-rw-r--r--ouptime/Makefile8
-rw-r--r--ouptime/ouptime.ml35
2 files changed, 43 insertions, 0 deletions
diff --git a/ouptime/Makefile b/ouptime/Makefile
new file mode 100644
index 0000000..f5dd316
--- /dev/null
+++ b/ouptime/Makefile
@@ -0,0 +1,8 @@
+make:
+ ocamlc unix.cma str.cma ouptime.ml -o ouptime
+
+static:
+ ocamlopt unix.cmxa -ccopt -static ouptime.ml -o ouptime
+
+clean:
+ rm -f *.cmi *.cmx *.o *.cmo \ No newline at end of file
diff --git a/ouptime/ouptime.ml b/ouptime/ouptime.ml
new file mode 100644
index 0000000..41b497c
--- /dev/null
+++ b/ouptime/ouptime.ml
@@ -0,0 +1,35 @@
+open Arg
+
+let default_procfs_dir = "/Process"
+let default_uptime_path = ref (String.concat "" (List.append [default_procfs_dir] ["/uptime"]))
+
+let set_uptime_path dir = default_uptime_path := (String.concat "" (List.append [dir] ["/uptime"]))
+
+let read_data filename =
+ let ic = open_in filename in
+ try
+ let line = input_line ic in
+ close_in ic;
+ (line)
+ with e ->
+ close_in_noerr ic;
+ raise e
+
+let main =
+begin
+ (*
+ Printf.printf "%s\n" !default_uptime_path;
+ *)
+ let speclist =
+ [
+ ("-p",Arg.String (set_uptime_path),"Procfs directory")
+ ]
+ in let usage_msg = "ouptime - show system uptime"
+ in Arg.parse speclist print_endline usage_msg;
+ Printf.printf "%s\n" !default_uptime_path;
+ let uptime_string = read_data !default_uptime_path in
+ print_endline uptime_string;
+end
+
+
+let () = main