5

Is there any way to spawn a new independent process from the current running script?

I am trying to run a new script from an already running script. The new script should be independent of the one that called it.

Matt Sanders
  • 8,023
  • 3
  • 37
  • 49
Arham Chopra
  • 79
  • 1
  • 5
  • In what context? The browser? Node.js? Something else? – deceze May 27 '16 at 05:31
  • _"The new script should be independent of the one that called it."_ What do you mean by "independent"? Can you include `javascript` that you have tried at Question? – guest271314 May 27 '16 at 05:32
  • 2
    by indepenedent i mean that it should keep running even if the original process stops – Arham Chopra May 27 '16 at 05:36
  • take a look at this one http://stackoverflow.com/questions/10773564/which-would-be-better-for-concurrent-tasks-on-node-js-fibers-web-workers-or-t – Alex Baban May 27 '16 at 05:39

1 Answers1

8

You can use the 'detached' option and the unref() method to make child process independent.

const spawn = require('child_process').spawn;

const child = spawn(process.argv[0], ['child_program.js'], {
  detached: true,
  stdio: ['ignore']
});

child.unref();

Ref: Node.js document

Mekal
  • 340
  • 1
  • 10