You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spawn-ed detached unref-ed child process in Windows still prevents parent from exit #5614
child_processIssues and PRs related to the child_process subsystem.invalidIssues and PRs that are invalid.windowsIssues and PRs related to the Windows platform.
Thank you, the stdio: 'ignore' will do it. May be this should be added to the doc as well, in the last paragraph of the options.detached part (in addition to the child process behavior info).
@vsemozhetbyt This information is already in the documentation for options.detached:
When using the detached option to start a long-running process, the process will not stay running in the background after the parent exits unless it is provided with a stdio configuration that is not connected to the parent. If the parent's stdio is inherited, the child will remain attached to the controlling terminal.
The last sentence is the key part. The parent cannot exit if the child is still attached to parent's stdio streams because normally once the parent process exits, those streams go away.
@wzup: make up your mind. Either you want the parent to read data from child as a child, or not.. If the child is fully detached, then how'd you want the parent to directly get anything from it? Either don't detach and let the parent just read it like from normal child, or detach and read it like a normal independent processes do: get any normal IPC channel.. sockets, files, whatever. Simplest way probably would be to make the child to write its log to a temp file, and read that instead, etc.
child_processIssues and PRs related to the child_process subsystem.invalidIssues and PRs that are invalid.windowsIssues and PRs related to the Windows platform.
Activity
cjihrig commentedon Mar 9, 2016
Can you try setting the child process
stdioto something that doesn't depend on the parent process.mscdex commentedon Mar 9, 2016
Yes, you need to add something like
stdio: 'ignore'to yourspawn()options for the parent process to exit as expected.vsemozhetbyt commentedon Mar 9, 2016
Thank you, the
stdio: 'ignore'will do it. May be this should be added to the doc as well, in the last paragraph of theoptions.detachedpart (in addition to the child process behavior info).mscdex commentedon Mar 9, 2016
@vsemozhetbyt This information is already in the documentation for
options.detached:vsemozhetbyt commentedon Mar 9, 2016
Well, it says child process will not stay after the parent exits. It does not say parent process will not exit while the child stays.
mscdex commentedon Mar 9, 2016
The last sentence is the key part. The parent cannot exit if the child is still attached to parent's
stdiostreams because normally once the parent process exits, those streams go away.vsemozhetbyt commentedon Mar 9, 2016
If you say so)
wzup commentedon Jan 12, 2018
How to capture events from child process if I detach and unref it?
I need to get data from child process. If I set
ignoreI can't get data.I start an HTTP server in a child process. Since it works forever main process waits forever and can't finish.
How to deal with it in Node.js?
quetzalcoatl commentedon Jan 16, 2018
@wzup: make up your mind. Either you want the parent to read data from child as a child, or not.. If the child is fully detached, then how'd you want the parent to directly get anything from it? Either don't detach and let the parent just read it like from normal child, or detach and read it like a normal independent processes do: get any normal IPC channel.. sockets, files, whatever. Simplest way probably would be to make the child to write its log to a temp file, and read that instead, etc.