( pid: number, signal: string = 'SIGTERM', retries: number = 10 )
| 730 | } |
| 731 | |
| 732 | async function nukePID( |
| 733 | pid: number, |
| 734 | signal: string = 'SIGTERM', |
| 735 | retries: number = 10 |
| 736 | ) { |
| 737 | if (retries === 0) { |
| 738 | console.log(`pid ${pid} won't die, giving up`); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | // kill the process |
| 743 | try { |
| 744 | process.kill(pid, signal); |
| 745 | } catch (_e) { |
| 746 | // process does not exist |
| 747 | |
| 748 | console.log(`pid ${pid} is not running`); |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | await sleep(250); |
| 753 | |
| 754 | try { |
| 755 | // check if killed |
| 756 | process.kill(pid, 0); |
| 757 | } catch (_e) { |
| 758 | console.log(`pid ${pid} is not running`); |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | console.log(`pid ${pid} didn't exit, sending SIGKILL (retries ${retries})`); |
| 763 | await nukePID(pid, 'SIGKILL', retries - 1); |
| 764 | } |
| 765 | |
| 766 | export async function nukeProcessTree(pid: number, signal?: string) { |
| 767 | if (process.platform === 'win32') { |
no test coverage detected