1 /***********************************************************************/
5 /* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../../LICENSE. */
12 /***********************************************************************/
20 #include "unixsupport.h"
21 #include <sys/types.h>
23 static value
alloc_process_status(HANDLE pid
, int status
)
28 Field(st
, 0) = Val_int(status
);
30 res
= alloc_small(2, 0);
31 Field(res
, 0) = Val_long((intnat
) pid
);
37 enum { CAML_WNOHANG
= 1, CAML_WUNTRACED
= 2 };
39 static int wait_flag_table
[] = { CAML_WNOHANG
, CAML_WUNTRACED
};
41 CAMLprim value
win_waitpid(value vflags
, value vpid_req
)
44 DWORD status
, retcode
;
45 HANDLE pid_req
= (HANDLE
) Long_val(vpid_req
);
48 flags
= convert_flag_list(vflags
, wait_flag_table
);
49 if ((flags
& CAML_WNOHANG
) == 0) {
50 enter_blocking_section();
51 retcode
= WaitForSingleObject(pid_req
, INFINITE
);
52 if (retcode
== WAIT_FAILED
) err
= GetLastError();
53 leave_blocking_section();
56 uerror("waitpid", Nothing
);
59 if (! GetExitCodeProcess(pid_req
, &status
)) {
60 win32_maperr(GetLastError());
61 uerror("waitpid", Nothing
);
63 if (status
== STILL_ACTIVE
)
64 return alloc_process_status((HANDLE
) 0, 0);
67 return alloc_process_status(pid_req
, status
);