The only answers I've seen for starting a process is using something called child_process. But I want to spawn an entirely new process completely independent from my current running node process, is this possible?
kill(-pid) method on main process we can kill all processes that are in the same group of a child process with the same pid group. In my case, I only have one processes in this group. var spawn = require('child_process'). spawn; var child = spawn('my-command', {detached: true}); process.
In a single thread, the individual instance of node. js runs specifically and to take advantage of various ecosystems, a cluster of node. js is launched, to distribute the load. With the help of a cluster module, child processes can be created very easily sharing the server ports.
You can spawn a child process in a detached state, ignore the outputs, and remove the child from the parents event loop with child.unref()
.
This code will start someScript.sh
, and exit while keeping someScript.sh
running.
var spawn = require('child_process').spawn;
var child = spawn(__dirname + '/someScript.sh', [], {
detached: true ,
stdio: [ 'ignore', 'ignore', 'ignore' ]
});
child.unref();
For more detailed information and alternatives (such as logging output / etc), take a look at the documentation for spawn
. There are other examples there as well:
http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With