 +    p->fstdin = proc_stdin, p->fstdout = proc_stdout, p->fstderr = proc_stderr;
 +    p->cstdout = new_channel(FD(proc_stdout), p, p->stdout_cb > 0);
 +    p->cstderr = new_channel(FD(proc_stderr), p, p->stderr_cb > 0);
-+    g_child_watch_add(p->pid, p_exit, p);
++    if (p->exit_cb != LUA_REFNIL) g_child_watch_add(p->pid, p_exit, p);
 +    // Close unneeded handles.
 +    CloseHandle(proc_info.hThread);
 +    CloseHandle(stdin_read);

+    lua_pushfstring(L, "process (pid=%d)", p->pid);
+  else
+    lua_pushstring(L, "process (terminated)");
   return 1;
 }
 
+#if (GTK && !__APPLE__)
+/** __gc Lua metamethod. */
+static int lp_gc(lua_State *L) {

+  WaitForSingleObject(p->pid, INFINITE);
+  GetExitCodeProcess(p->pid, &status);
+#endif
+  exited(p, status);
+  return (lua_pushinteger(L, status), 1);
+}
+
