(************************************************************ processTest.ml Created : Sat Aug 31 00:47:18 2002 Last modified: Sat Aug 31 00:57:10 2002 Compile: ocamlopt.opt unix.cmxa str.cmxa processTest.ml -o processTest # ************************************************************) (** forkしたらどうよ? @author 増山隆 @see http://www002.upp.so-net.ne.jp/mamewo/ml.html *) let target1 = "hogehogeGEGE tak" let target2 = "mamewo mmmmmm" let regexp1 = Str.regexp "hogehoge\\(.+\\)$" let regexp2 = Str.regexp "\\(.+\\) mm" let entry (str,reg,sec) = let is_matched = Str.string_match reg str 0 in begin Unix.sleep sec; if is_matched then print_string ((Str.matched_group 1 str)^"\n") else print_string "not matched\n"; flush stdout; end let _ = let child_id = 0 in let id = Unix.fork () in if id = child_id then entry (target1,regexp1,10) else begin entry (target2,regexp2,0); ignore (Unix.wait ()) end