2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: system.c,v 1.15 2001/06/29 11:35:14 simonpj Exp $
6 * system Runtime Support
9 /* The itimer stuff in this module is non-posix */
10 #define NON_POSIX_SOURCE
14 #if defined(mingw32_TARGET_OS)
21 /* -------------------- WINDOWS VERSION --------------------- */
22 #if defined(mingw32_TARGET_OS)
24 PROCESS_INFORMATION pInfo;
27 sInfo.cb = sizeof(STARTUPINFO);
28 sInfo.lpReserved = NULL;
29 sInfo.lpReserved2 = NULL;
30 sInfo.cbReserved2 = 0;
31 sInfo.lpDesktop = NULL;
35 if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo))
37 WaitForSingleObject(pInfo.hProcess, INFINITE);
38 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
39 CloseHandle(pInfo.hProcess);
40 CloseHandle(pInfo.hThread);
44 /* -------------------- UNIX VERSION --------------------- */
48 switch(pid = fork()) {
56 /* Reset the itimers in the child, so it doesn't get plagued
57 * by SIGVTALRM interrupts.
59 struct timeval tv_null = { 0, 0 };
61 itv.it_interval = tv_null;
62 itv.it_value = tv_null;
63 setitimer(ITIMER_REAL, &itv, NULL);
64 setitimer(ITIMER_VIRTUAL, &itv, NULL);
65 setitimer(ITIMER_PROF, &itv, NULL);
69 execl("/bin/sh", "sh", "-c", cmd, NULL);
74 while (waitpid(pid, &wstat, 0) < 0) {
81 return WEXITSTATUS(wstat);
82 else if (WIFSIGNALED(wstat)) {
86 /* This should never happen */