How to use the child_process.fork function in child_process

To help you get started, we’ve selected a few child_process examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ioBroker / ioBroker.iot / test / lib / setup.js View on Github external
console.log('Install adapter...');
    var startFile = 'node_modules/' + appName + '.js-controller/' + appName + '.js';
    // make first install
    if (debug) {
        child_process.execSync('node ' + startFile + ' add ' + customName + ' --enabled false', {
            cwd:   rootDir + 'tmp',
            stdio: [0, 1, 2]
        });
        checkIsAdapterInstalled(function (error) {
            if (error) console.error(error);
            console.log('Adapter installed.');
            if (cb) cb();
        });
    } else {
        // add controller
        var _pid = child_process.fork(startFile, ['add', customName, '--enabled', 'false'], {
            cwd:   rootDir + 'tmp',
            stdio: [0, 1, 2, 'ipc']
        });

        waitForEnd(_pid, function () {
            checkIsAdapterInstalled(function (error) {
                if (error) console.error(error);
                console.log('Adapter installed.');
                if (cb) cb();
            });
        });
    }
}
github expo / xde / src / application / PackagerController.js View on Github external
let cliOpts = ['start',
      '--port', this.opts.packagerPort,
      '--projectRoots', root,
      '--assetRoots', root,
    ];

    if (options.reset) {
      cliOpts.push('--reset-cache');
    }
    
    // Run the copy of Node that's embedded in Electron by setting the
    // ELECTRON_RUN_AS_NODE environment variable
    // Note: the CLI script sets up graceful-fs and sets ulimit to 4096 in the
    // child process
    let packagerProcess = child_process.fork(this.opts.cliPath, cliOpts, {
      cwd: path.dirname(path.dirname(this.opts.cliPath)),
      env: {
        ...process.env,
        NODE_PATH: null,
        ELECTRON_RUN_AS_NODE: 1,
      },
      silent: true,
    });
    process.on('exit', () => {
      packagerProcess.kill();
    });
    this._packager = packagerProcess;
    this._packager.stdout.setEncoding('utf8');
    this._packager.stderr.setEncoding('utf8');
    this._packager.stdout.on('data', (data) => {
      this.emit('stdout', data);
github harpagon210 / steemsmartcontracts / test / blockproduction.js View on Github external
const loadPlugin = (newPlugin) => {
  const plugin = {};
  plugin.name = newPlugin.PLUGIN_NAME;
  plugin.cp = fork(newPlugin.PLUGIN_PATH, [], { silent: true });
  plugin.cp.on('message', msg => route(msg));
  plugin.cp.stdout.on('data', data => console.log(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
  plugin.cp.stderr.on('data', data => console.error(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));

  plugins[newPlugin.PLUGIN_NAME] = plugin;

  return send(newPlugin.PLUGIN_NAME, 'MASTER', { action: 'init', payload: conf });
};
github jivesoftware / jive-sdk / test / _functional_old / test-util.js View on Github external
function createServer(config, procOptions) {
    var deferred = q.defer();

    if (!procOptions) {
        procOptions = {};
    }
    procOptions.execArgv = [];
    var serverProcess = require('child_process').fork('./test-server',  procOptions);

    var serverStartedCallback = function(m) {

        serverProcess.removeListener('message', arguments.callee);
        var success = m.serverStarted;
        if (success) {
            deferred.resolve(serverProcess);
        }
        else {
            deferred.reject('Failure starting test server' + JSON.stringify(m));
            console.log("Failure starting test server!");
        }

    };

    //Setup listener for when server starts and sends a message back
github salesforce / refocus / tests / clock / utils / utils.js View on Github external
function doFork(path, args, env) {
  path = require.resolve(path);
  const opts = {
    silent: true,
    env,
  };

  const subprocess = fork(path, args, opts);
  subprocess.stdout.on('data', (data) => logger.info(data.toString()));
  subprocess.stderr.on('data', (data) => console.error(data.toString()));
  return subprocess;
}
github instana / nodejs-sensor / test / util / control.js View on Github external
beforeEach(() => {
    if (!this.opts.faasRuntimePath) {
      fail('opts.faasRuntimePath is unspecified.');
    } else if (!this.opts.handlerDefinitionPath) {
      fail('opts.handlerDefinitionPath is unspecified.');
    }

    this.messagesFromBackend = [];
    this.messagesFromDownstreamDummy = [];
    this.messagesFromFaasRuntime = [];

    let backendPromise;
    if (this.opts.startBackend) {
      this.backend = fork(path.join(__dirname, '../backend_stub'), {
        stdio: config.getAppStdio(),
        env: Object.assign(
          {
            BACKEND_PORT: config.backendPort,
            BACKEND_UNRESPONSIVE: this.opts.startBackend === 'unresponsive'
          },
          process.env,
          this.opts.env
        )
      });
      this.backend.on('message', message => {
        this.messagesFromBackend.push(message);
      });
      backendPromise = this.waitUntilBackendIsUp();
    } else {
      backendPromise = Promise.resolve();
github harpagon210 / steemsmartcontracts / benchmarks / load.js View on Github external
const loadPlugin = (newPlugin) => {
  const plugin = {};
  plugin.name = newPlugin.PLUGIN_NAME;
  plugin.cp = fork(newPlugin.PLUGIN_PATH, [], { silent: true, detached: true });
  plugin.cp.on('message', msg => route(msg));
  plugin.cp.stdout.on('data', data => console.log(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
  plugin.cp.stderr.on('data', data => console.error(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));

  plugins[newPlugin.PLUGIN_NAME] = plugin;

  return send(plugin, { action: 'init', payload: conf });
};
github wuchangming / spy-debugger / lib / proxy / spyProxy.js View on Github external
var restartFun = function restartFun() {
                    console.log(colors.yellow('anyproxy\u5F02\u5E38\u9000\u51FA\uFF0C\u5C1D\u8BD5\u91CD\u542F'));
                    var childProxy = childProcess.fork(__dirname + '/externalChildProcess');
                    childProxy.send({
                        type: 'restart',
                        ports: ports
                    });
                    childProxy.on('exit', function (e) {
                        restartFun();
                    });
                };
                childProxy.on('exit', function (e) {
github harpagon210 / steemsmartcontracts / app.js View on Github external
const loadPlugin = (newPlugin) => {
  const plugin = {};
  plugin.name = newPlugin.PLUGIN_NAME;
  plugin.cp = fork(newPlugin.PLUGIN_PATH, [], { silent: true, detached: true });
  plugin.cp.on('message', msg => route(msg));
  plugin.cp.stdout.on('data', (data) => {
    logger.info(`[${newPlugin.PLUGIN_NAME}] ${data.toString()}`);
  });
  plugin.cp.stderr.on('data', (data) => {
    logger.error(`[${newPlugin.PLUGIN_NAME}] ${data.toString()}`);
  });

  plugins[newPlugin.PLUGIN_NAME] = plugin;

  return send(plugin, { action: 'init', payload: conf });
};
github ritzyed / ritzy / gulpfile.js View on Github external
var server = (function startup() {
    var child = cp.fork(paths.build + '/server.js', nodeArgs, {
      env: assign({NODE_ENV: 'development'}, process.env)
    })
    child.once('message', function(message) {
      if (message.match(/^online$/)) {
        if (browserSync) {
          browserSync.reload()
        }
        if (!started) {
          started = true
          gulp.watch(src.server, function() {
            $.util.log('Restarting development server.')
            server.kill('SIGTERM')
            server = startup()
          })
          cb()
        }

child_process

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

ISC
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis