Skip to content

Commit 23122d3

Browse files
authored
Update cleanup.js
1 parent 1db277e commit 23122d3

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

cleanup.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
const isWindows = process.platform === 'win32';
22

33
const kill = (process) => {
4-
if (isWindows) {
5-
const kill = require('tree-kill');
6-
kill(process.pid);
7-
} else {
8-
process.kill('SIGINT');
9-
}
4+
console.log(`Attempting to kill process with PID: ${process.pid}`);
5+
if (isWindows) {
6+
const { spawn } = require('child_process');
7+
// used taskkill for Windows to terminate the process tree
8+
const taskKill = spawn('taskkill', ['/PID', process.pid, '/T', '/F']);
9+
taskKill.on('close', (code) => {
10+
if (code === 0) {
11+
console.log('Process killed successfully on Windows.');
12+
} else {
13+
console.error(`taskkill failed with exit code: ${code}`);
14+
}
15+
});
16+
} else {
17+
try {
18+
process.kill('SIGINT');
19+
console.log('SIGINT sent to process');
20+
} catch (error) {
21+
console.error(`Failed to send SIGINT: ${error.message}`);
22+
}
23+
}
1024
};
1125

1226
module.exports = { kill };

0 commit comments

Comments
 (0)