node/test/parallel/test-child-process-fork-detached.js
timothy searcy f051737ee4 test: test and docs for detached fork process
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: https://github.com/nodejs/node/issues/17592

PR-URL: https://github.com/nodejs/node/pull/24524
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-11-28 11:14:37 -08:00

24 lines
563 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const fork = require('child_process').fork;
const fixtures = require('../common/fixtures');
const nonPersistentNode = fork(
fixtures.path('parent-process-nonpersistent-fork.js'),
[],
{ silent: true });
let childId = -1;
nonPersistentNode.stdout.on('data', (data) => {
childId = parseInt(data, 10);
nonPersistentNode.kill();
});
process.on('exit', () => {
assert.notStrictEqual(childId, -1);
// Killing the child process should not throw an error
process.kill(childId);
});