2 * Copyright (C) 2014-2015 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 (* Simple forking parallel primitives. *)
27 let rfd, wfd = pipe () in
36 let y = Printexc.catch f x in
37 (* Write the final value to the pipe. *)
38 output_value (out_channel_of_descr wfd) y;
49 (* Read all the output from the pipe. *)
50 let buf = Buffer.create 13 in
51 let bytes = Bytes.create 4096 in
53 let len = read rfd bytes 0 (Bytes.length bytes) in
55 Buffer.add_subbytes buf bytes 0 len;
60 let str = Buffer.to_bytes buf in
62 (* Wait for the subprocess. *)
63 match waitpid [] pid with
66 eprintf "mclu: subprocess pid %d died with exit status %d\n" pid i;
70 eprintf "mclu: subprocess pid %d died with signal %d\n" pid i;
74 eprintf "mclu: subprocess pid %d stopped with signal %d\n" pid i;
84 let iter f xs = ignore (map f xs)