Replies: 2 comments 1 reply
-
|
After doing some more experimenting, I might have found the issue. I'm using UV_INHERIT_FD for stdout and stderr. I'm passing an stdios[0].flags = UV_IGNORE;
stdios[1].flags = UV_INHERIT_FD;
stdios[1].data.fd = 1;
stdios[2].flags = UV_INHERIT_FD;
stdios[2].data.fd = 2;
options.stdio = stdios;
options.stdio_count = 3;When I remove that code, the child process is closed correctly, in the correct order. If this is indeed the the issue, then I'm curious how I should correctly deal with this when respawning the child process? |
Beta Was this translation helpful? Give feedback.
-
Libuv doesn't shut down child processes, not unless you tell it to with uv_process_kill. It's hard to give concrete advice without knowing more about your program but you're most likely experiencing standard UNIX process behavior. Is your expectation that terminating the parent process also results in child termination? That's definitely not the case, although it sometimes looks that way: e.g. typing ^C sends SIGINT not just to the foreground process but to the entire process group. Vice versa, sending SIGINT to a PID sends it to just that one process, it doesn't fan out across the process group. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on a process manager with a single "pm" executable that starts a child process using
uv_spawn(). I can send messages over a TCP socket to start or stop this child process. That part works fine, but I'm running into a situation where I'm clearly missing some understanding of how libuv shuts down child processes. I can provide more details if needed, but I'll try to explain the situation as clearly as possible.Here's the weird part: when I start the process manager and immediately start the child process, then send a SIGINT to the process manager, both processes stop correctly. The process manager exits first, then the child process, and my terminal returns to the prompt as expected.
But if I restart the child process through a message over the network and then send SIGINT to the process manager, things go wrong. In that case, the process manager exits first, before the child process. I confirmed this by adding a
printf()right before returning frommain(). When this happens, my terminal never returns to the prompt. Instead, it just shows the lastprintf()from the child process.I understand that without pasting the code there might be by a dozen reasons why I'm seeing this behavior, though maybe I'm missing something obvious and therefore I'm curious how to correctly stop the child process and loop when spawning child processes in general.
One potentially important note is, that when I add a
uv_sleep(1000), right after theuv_run(loop, UV_RUN_DEFAULT), that the processes exit in the correct order: child process exists first, then the process manager and my prompt returns.Beta Was this translation helpful? Give feedback.
All reactions