let cin = open_in (Printf.sprintf "/proc/%i/status" pid) in
let matchline s =
try
- Scanf.sscanf s " VmHWM: %i kB" (fun i -> Some i)
+ Scanf.sscanf s " VmRSS: %i kB" (fun i -> Some i)
with
| _ -> None
in
| None -> loop ()
in
let s = try loop() with _ -> -1 in
+ Printf.eprintf "Memory: %i\n%!" s;
close_in cin;
s
;;
if p == 0 then
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
+ if (Unix.gettimeofday() > timeout)
+ then let () = Printf.eprintf "Timeout reached, killing child process\n%!" in
+ Unix.kill pid Sys.sigkill
+ else if !max_mem >= mem
+ then let () = Printf.eprintf "Memory limit reached, killing child process\n%!" in
+ Unix.kill pid Sys.sigkill
else
- let () = Unix.sleep 1 in
+ let () = Unix.sleep 1 in
monitor pid timeout mem
;;