projects
/
SXSI
/
xpathcomp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Revert changes for following-sibling jumping function for now.
[SXSI/xpathcomp.git]
/
utils
/
alarm.ml
diff --git
a/utils/alarm.ml
b/utils/alarm.ml
index
a12936c
..
8874756
100644
(file)
--- 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 =
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
;;
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
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
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
;;
else monitor pid timeout mem
;;
-let () =
+let () =
if Array.length Sys.argv < 4 then exit 1
else
try
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;
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
exit 0
with
_ -> exit 2