summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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