From ea30aa946ef4b441d05c003bd74a65b5a67de3c5 Mon Sep 17 00:00:00 2001 From: dianshi Date: Mon, 29 Jun 2020 22:30:24 +0100 Subject: Add ouptime --- ouptime/Makefile | 8 ++++++++ ouptime/ouptime.ml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 ouptime/Makefile create mode 100644 ouptime/ouptime.ml 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 -- cgit v1.2.3