-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Run process detached from its parent on Linux #42
Conversation
What OS are you on? This option seems to do exactly what we want |
I'm on Linux. I don't really understand how I do recognize that this solution is probably not optimal since increasing the number of options adds up complexity. Do you think that |
Well, you're doing exactly the same thing, except that you're waiting for the process to exit before resolving the Promise. I don't have a Linux system available so I'm afraid I can't debug it further though. |
Thanks for the quick reply. I think I finally understood what you meant. I have now changed the code so that when wait is false it sets The node.js docs show this example for detaching child processes in order to let them run after the parent exits: const { spawn } = require('child_process');
const subprocess = spawn(process.argv[0], ['child_program.js'], {
detached: true,
stdio: 'ignore'
});
subprocess.unref(); This is what I want I do believe that this issue occurs on all platforms but I'd like to be proven wrong so here's a test plan. Consider the following script: const opn = require('opn')
opn('https://fsf.org', { app: 'google-chrome-stable', wait: false}).then(() => {
console.log('promise fulfilled')
})
while(true); It just opens Google Chrome and with After the page loads, terminate the script with What should happen is that the script exits, but the browser keeps running. Why? Because node forwards the interrupt signal to the child process. The only way to avoid it to detach the child process from its parent. |
I can't reproduce this behaviour in |
I can confirm using |
@W1lkins, thanks for testing. @GAumala, could you just move the |
On platforms that use xdg-open, if waiting option is false set stdio to 'ignore' and detached to true so that the xdg-open process is completely detached from the parent and it is able to continue running after the parent exits.
Yes it seems I've been looking at this at the wrong level. Probably the bug is related to |
Add option 'detached' to allow the opened app to continue running after the
parent process exits.
in Linux and MacOS if this option is true, the child process
stdio
isset to 'ignore'.
The reason for this change is that I use
opn
to open a browser, but I don't want the browser to get closed when the node.js process exits, which is what currently happens, even if I setwait
to false. The code is a bit messy because this option seems to conflic withwait
. According to the docs, to spawn a child process so that it can continue after parent exits 2 options are needed:detached
true.stdio
to 'ignore'.it might be better add
stdio
option as well instead of just asuming thatdetached
true implies the value ofstdio
.