-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I think child_process.fork() should officially support { detached: true } #17592
Comments
I can think of at least one corner case, but it's probably unlikely to be affected since no code changes would be required. Code that checks for the existence of APIs like If it works already, people find it useful, and no one has a good reason not to support it, then we probably should document it (although I still think |
I'd be happy to work on a PR for this if the idea goes through! 👍 |
FTR: this is basically a "need to document and test" issue. |
Hi @refack. I would love to contribute to this issue as my first issue. Would this be testing the functionality that @mmorearty documented?
From some quick research I think the path would be to create a file named There I would be creating the test for the above code. Then I might follow the test Did I miss anything? Edit: does this look right? Also where would I update the documentation for this? |
This tests child process fork component in detached mode by spawning a parent process that creates a child process. We kill the parent process and check if the child is still running. Fixes: nodejs#17592
This tests child process fork component in detached mode by spawning a parent process that creates a child process. We kill the parent process and check if the child is still running. Fixes: nodejs#17592 PR-URL: nodejs#24524 Reviewed-By: Luigi Pinca <[email protected]>
Fixed in f051737 |
This tests child process fork component in detached mode by spawning a parent process that creates a child process. We kill the parent process and check if the child is still running. Fixes: #17592 PR-URL: #24524 Reviewed-By: Luigi Pinca <[email protected]>
This tests child process fork component in detached mode by spawning a parent process that creates a child process. We kill the parent process and check if the child is still running. Fixes: nodejs#17592 PR-URL: nodejs#24524 Reviewed-By: Luigi Pinca <[email protected]>
This tests child process fork component in detached mode by spawning a parent process that creates a child process. We kill the parent process and check if the child is still running. Fixes: #17592 PR-URL: #24524 Reviewed-By: Luigi Pinca <[email protected]>
This tests child process fork component in detached mode by spawning a parent process that creates a child process. We kill the parent process and check if the child is still running. Fixes: #17592 PR-URL: #24524 Reviewed-By: Luigi Pinca <[email protected]>
child_process.spawn()
supports an optiondetached
which "makes it possible for the child process to continue running after the parent exits."child_process.fork()
does not officially supportdetached
as one of its options (by "officially support", I mean that it is not documented as a valid option); but I think it should be officially supported.My reasons:
If you agree, then no code changes would be required, but the documentation for
child_process.fork()
would need to listdetached
as a valid option. (Also, TypeScript's@types/node
would need to be updated, but that would probably be a separate GitHub issue somewhere else.)1. It works today: First of all, if you look at the current source for
child_process.fork()
, it's clear (and not surprising) thatfork()
is just a simple wrapper aroundspawn()
. It passes most options through unchanged.To prove that
detached
works withfork()
: save this as demo.js:To see the NON-detached behavior, launch it with
node demo.js
. It will callfork()
, so there are now two instances running. Then press ^C; if you dops aux | grep demo.js
you will see that both instances terminated.To see the detached behavior, repeat the above but with
node demo.js detached
. In this case, after ^C, the child process is still running.2. It's useful:
child_process.fork()
can be useful for starting daemon processes, anddetached
is certainly useful for daemons.The text was updated successfully, but these errors were encountered: