test('error.signal is SIGINT', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid, 'SIGINT'); const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/}); t.is(signal, 'SIGINT'); });
test.cb('sanity check: child_process.exec also has killed.false if killed indirectly', t => { const {pid} = childProcess.exec('noop', error => { t.truthy(error); t.false(error.killed); t.end(); }); process.kill(pid, 'SIGINT'); });
signalTraps.map(type => { process.once(type, async () => { try { await admin.disconnect() } finally { process.kill(process.pid, type) } }) })
// When parent process exits before child process const spawnAndKill = async (t, signal, cleanup, detached, isKilled) => { const subprocess = execa('sub-process', [cleanup, detached], {stdio: ['ignore', 'ignore', 'ignore', 'ipc']}); const pid = await pEvent(subprocess, 'message'); t.true(Number.isInteger(pid)); t.true(isRunning(pid)); process.kill(subprocess.pid, signal); await t.throwsAsync(subprocess); t.false(isRunning(subprocess.pid)); t.is(isRunning(pid), !isKilled); if (isRunning(pid)) { process.kill(pid, 'SIGKILL'); } }
test('detach child process', async t => { const {stdout} = await execa('detach'); const pid = Number(stdout); t.true(Number.isInteger(pid)); t.true(isRunning(pid)); process.kill(pid, 'SIGKILL'); });
test('error.killed is false if process was killed indirectly', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid, 'SIGINT'); // `process.kill()` is emulated by Node.js on Windows const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/; const {killed} = await t.throwsAsync(subprocess, {message}); t.false(killed); });
self.running = false; try { process.kill(-proc.pid); resolve(-1); } catch (err) {
private async killDaemon() { const pid = await this.readPidDaemonConfig(); if (!pid) { console.log('Daemon is not running!'); return; } if (await this.isDaemonRunning()) { console.log(`Daemon process ${pid} Killed!`); process.kill(pid); } }
function killPid(pid, signal) { try { process.kill(pid, signal); } catch (err) { throw new Error_1.LiveInspectorError("Failed to send signal to pid: " + pid + ", is the process still alive?"); } }
test('error.signalDescription is defined', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid, 'SIGINT'); const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/}); t.is(signalDescription, 'User interruption with CTRL-C'); });
test('error.signal is SIGTERM', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid, 'SIGTERM'); const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/}); t.is(signal, 'SIGTERM'); });
test('exitCode is undefined on signal termination', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid); const {exitCode} = await t.throwsAsync(subprocess); t.is(exitCode, undefined); });
signalTraps.map(type => { process.once(type, async () => { try { await consumer.disconnect() } finally { process.kill(process.pid, type) } }) })
signalTraps.map(type => { process.once(type, async () => { try { await producer.disconnect() } finally { process.kill(process.pid, type) } }) })
private async killDaemon() { const pid = await this.readPidDaemonConfig(); if (!pid) { console.log('Daemon is not running!'); return; } if (await this.isDaemonRunning()) { console.log(`Daemon process ${pid} Killed!`); process.kill(pid); } }