forked from os-fpga/rapid_power_estimator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.js
36 lines (34 loc) · 1.26 KB
/
cleanup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const os = require('os');
const platform = os.platform();
const kill = (process) => {
console.log(`Attempting to kill process with PID: ${process.pid}`);
const { spawn } = require('child_process');
if (platform === 'win32') {
// used taskkill for Windows to terminate the process tree
const taskKill = spawn('taskkill', ['/PID', process.pid, '/T', '/F']);
taskKill.on('close', (code) => {
if (code === 0) {
console.log('Process killed successfully on Windows.');
} else {
console.error(`taskkill failed with exit code: ${code}`);
}
});
} else if (platform === 'darwin' || platform === 'linux') {
const taskKill = spawn('kill', ['-9', process.pid]);
taskKill.on('close', (code) => {
if (code === 0) {
console.log('Process killed successfully on Unix.');
} else {
console.error(`taskkill failed with exit code: ${code}`);
}
});
} else {
try {
process.kill('SIGINT');
console.log('SIGINT sent to process');
} catch (error) {
console.error(`Failed to send SIGINT: ${error.message}`);
}
}
};
module.exports = { kill };