Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function() {
if (!global.appProcess) return
const pid = global.appProcess.pid
for (let i = 0; true; i++) {
// console.log('checking if killed', await processExists(pid))
if (!(await processExists(pid))) {
return
}
await sleep(100)
// 10 min
if (i > 10 * 60 * 10) {
console.log('App stop timeout')
return
}
}
}
const fkill = async (inputs, options = {}) => {
inputs = arrify(inputs)
options.tree = options.tree === undefined ? true : options.tree
options.ignoreCase = options.ignoreCase || process.platform === 'win32'
const exists = await processExists.all(inputs)
const errors = []
const handleKill = async input => {
try {
input = await parseInput(input)
if (input === process.pid) {
return
}
// Handle killall by process name
if (typeof input === 'string') {
const processes = await psList()
const nameRe = new RegExp(`^${input}$`, options.ignoreCase ? 'i' : '')
const interval = setInterval(async () => {
const [, isRunning] = await eres(processExists(processName));
if (!isRunning) {
clearInterval(interval);
setTimeout(resolve, 1000);
}
}, 500);
});
const fkill = async (inputs, options = {}) => {
inputs = arrify(inputs);
const exists = await processExists.all(inputs);
const errors = [];
const handleKill = async input => {
try {
input = await parseInput(input);
if (input === process.pid) {
return;
}
if (input === 'node') {
const processes = await psList();
await Promise.all(processes.map(async ps => {
if (ps.name === 'node' && ps.pid !== process.pid) {
await kill(ps.pid, options);