10 examples of 'kill node process' in JavaScript

Every line of 'kill node process' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
75kill() {
76 Object.keys(this.__threads).forEach(threadId => {
77 this.__threads[threadId].kill();
78 });
79 this.__threads = {};
80}
14export async function killProcessTree(processName: string, verbose = false) {
15 const list = execSync(`ps ax | grep ${processName}`)
16 .toString('utf8')
17 .trim();
18 debug('list of ' + processName);
19 debug(list);
20
21 // get the parent PID of this process
22 const selfPID = process.pid.toString();
23 const ppid = execSync(`ps -p ${selfPID} -o ppid=`)
24 .toString('utf8')
25 .trim();
26
27 // TODO parallel
28 for (const line of list.split('\n')) {
29 try {
30 // skip gres
31 if (line.includes('grep')) {
32 continue;
33 }
34 const pid = line.match(/^\s*(\d+)/)[1];
35 debug(`PID ${pid}`);
36 // never kill yourself
37 if (pid === selfPID || pid === ppid) {
38 continue;
39 }
40 if (verbose) {
41 log(`Killing PID tree ${pid} of ${processName}`);
42 }
43 await killAsync(parseInt(pid, 10));
44 } catch (err) {
45 log(err);
46 }
47 }
48}
28public kill(): void {
29 const kill = require("tree-kill");
30 kill(this.angularProcess.pid, "SIGKILL");
31}
26public kill() {
27 if (this._pid && typeof this._pid === 'number') {
28 try {
29 let kill = require('tree-kill');
30 kill(this._pid!);
31 this._pid = undefined;
32 } catch (e) {
33 }
34
35 }
36}
28function killSingleProcess(pid, callback) {
29 callback = callback || noop;
30 pid = pid.toString();
31
32 if (isWin) {
33 // "taskkill /F /PID 827"
34 exec("taskkill /F /PID " + pid, function (err, stdout, stderr) {
35 callback(err ? fixEOL(stderr) : undefined, err ? undefined : fixEOL(stdout));
36 });
37 } else {
38 // "kill -9 2563"
39 exec("kill -9 " + pid, function (err, stdout, stderr) {
40 callback(err ? fixEOL(stderr) : undefined, err ? undefined : fixEOL(stdout));
41 });
42 }
43}
38killAll() {
39 for (let i = 0; i < this.processes.length; i += 1) {
40 this.processes[i].kill();
41 }
42}
124function killNode(next) {
125 helper.ccmHelper.exec(['node1', 'stop'], next);
126},
22public async kill(signal?: string): Promise {
23 this.instance.kill(signal)
24}
240async function killPromise(processId: number) {
241 return new Promise((resolve, reject) => {
242 kill(processId, 'SIGKILL', (err: {}) => {
243 err ? reject(err) : resolve();
244 });
245 });
246}
43async killServer(): Promise {
44 const server = this.currentServer;
45
46 return new Promise((resolve, reject) => {
47 if (server == null) {
48 return resolve();
49 }
50
51 // remove all exit listeners so we won't log an error after spawn
52 server.removeAllListeners('exit');
53
54 terminate(server.pid, 30000).then(resolve).catch(reject);
55 });
56}

Related snippets