X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=utils%2Falarm.ml;h=8874756906fc45966322a746678ceac011a8d314;hb=37179f8e1c5fc279ef6ae7202065825f3a9c052c;hp=a12936c3bed775d36add079b2db33ddcaa58da68;hpb=4b52da1a20a4fe031930bb96d2ca46bec06dc529;p=SXSI%2Fxpathcomp.git diff --git a/utils/alarm.ml b/utils/alarm.ml index a12936c..8874756 100644 --- a/utils/alarm.ml +++ b/utils/alarm.ml @@ -1,4 +1,3 @@ - let read_procmem pid = let cin = open_in (Printf.sprintf "/proc/%i/status" pid) in let matchline s = @@ -16,11 +15,13 @@ let read_procmem pid = close_in cin; s ;; - +let max_mem = ref 0 let rec monitor pid timeout mem = let p, s = Unix.waitpid [ Unix.WNOHANG ] pid in if p == 0 then - if (Unix.gettimeofday() > timeout || (read_procmem pid) >= mem) + let current_mem = read_procmem pid in + if current_mem >= !max_mem then max_mem := current_mem; + if (Unix.gettimeofday() > timeout || current_mem >= mem) then Unix.kill pid Sys.sigkill else let () = Unix.sleep 1 in @@ -35,7 +36,7 @@ let run args timeout mem = else monitor pid timeout mem ;; -let () = +let () = if Array.length Sys.argv < 4 then exit 1 else try @@ -43,6 +44,7 @@ let () = let mem = int_of_string Sys.argv.(2) in let command = Array.sub Sys.argv 3 ((Array.length Sys.argv) - 3) in run command timeout mem; + Printf.printf "Child process used %i kB of memory\n%!" !max_mem; exit 0 with _ -> exit 2