I am creating a process using LibUV on Visual Studio 15.
I want to do something like this :
createsProcess() {
pid_t pid;
pid = myspawn(cmd, argv, my_fds, 1);
while(waitpid(&pid, child_status,0 == -1 && errno = EINTR));
}
}
The code for process creation:
pid_t myspawn(char* cmd, char **argv, int* mapped_fds) {
pid_t pid;
extern char** environ;
uv_loop_t *loop;
uv_process_t child_req;
uv_process_options_t options = { 0 }; //-- Default initialization must be 0
loop = uv_default_loop();
//-- Container for file descriptor
uv_stdio_container_t child_stdio[3];
child_stdio[0].flags = UV_IGNORE;
child_stdio[1].flags = UV_INHERIT_FD; //STD_OUT should be redirected to calling function
child_stdio[2].flags = UV_IGNORE;
// Pass stdout of created process to parent passed descriptor.
if (mapped_fds != NULL) {
for (; *mapped_fds != -1; mapped_fds += 2) {
if (mapped_fds[1] != -1)
child_stdio[1].data.fd = mapped_fds[0];
}
}
options.stdio = child_stdio;
options.exit_cb = on_exit;
options.file = cmd;
options.args = argv;
options.env = environ;
errno = uv_spawn(loop,&child_req,&options);
pid = child_req.pid;
if (errno != 0)
return -1;
return pid;
}
The problem is windows doesn't have any support for waitpid(), and I am unable to find an alternative in LibUV that exactly does same. However I can only call a function like on_exit when the child process exits. But that doesn't help me to wait for it.
Any help would be appreciated.
Best