MCPcopy
hub / github.com/remy/nodemon / kill

Function kill

lib/monitor/run.js:338–438  ·  view source on GitHub ↗
(child, signal, callback)

Source from the content-addressed store, hash-verified

336}
337
338function kill(child, signal, callback) {
339 if (!callback) {
340 callback = noop;
341 }
342
343 if (utils.isWindows) {
344 const taskKill = () => {
345 try {
346 exec('taskkill /pid ' + child.pid + ' /T /F');
347 } catch (e) {
348 utils.log.error('Could not shutdown sub process cleanly');
349 }
350 };
351
352 // We are handling a 'SIGKILL' , 'SIGUSR2' and 'SIGUSR1' POSIX signal under Windows the
353 // same way it is handled on a UNIX system: We are performing
354 // a hard shutdown without waiting for the process to clean-up.
355 if (
356 signal === 'SIGKILL' ||
357 osRelease < 10 ||
358 signal === 'SIGUSR2' ||
359 signal === 'SIGUSR1'
360 ) {
361 debug('terminating process group by force: %s', child.pid);
362
363 // We are using the taskkill utility to terminate the whole
364 // process group ('/t') of the child ('/pid') by force ('/f').
365 // We need to end all sub processes, because the 'child'
366 // process in this context is actually a cmd.exe wrapper.
367 taskKill();
368 callback();
369 return;
370 }
371
372 try {
373 // We are using the Windows Management Instrumentation Command-line
374 // (wmic.exe) to resolve the sub-child process identifier, because the
375 // 'child' process in this context is actually a cmd.exe wrapper.
376 // We want to send the termination signal directly to the node process.
377 // The '2> nul' silences the no process found error message.
378 const resultBuffer = execSync(
379 `wmic process where (ParentProcessId=${child.pid}) get ProcessId 2> nul`
380 );
381 const result = resultBuffer.toString().match(/^[0-9]+/m);
382
383 // If there is no sub-child process we fall back to the child process.
384 const processId = Array.isArray(result) ? result[0] : child.pid;
385
386 debug('sending kill signal SIGINT to process: %s', processId);
387
388 // We are using the standalone 'windows-kill' executable to send the
389 // standard POSIX signal 'SIGINT' to the node process. This fixes #1720.
390 const windowsKill = path.normalize(
391 `${__dirname}/../../bin/windows-kill.exe`
392 );
393
394 // We have to detach the 'windows-kill' execution completely from this
395 // process group to avoid terminating the nodemon process itself.

Callers 1

run.jsFile · 0.85

Calls 4

taskKillFunction · 0.85
callbackFunction · 0.85
execFunction · 0.85
waitForSubProcessesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…