| 155 | public logger = logger.named(`child:${process.pid}`) |
| 156 | |
| 157 | public constructor(private readonly parentPid: number) { |
| 158 | super() |
| 159 | |
| 160 | // Kill the inner process if the parent dies. This is for the case where the |
| 161 | // parent process is forcefully terminated and cannot clean up. |
| 162 | setInterval(() => { |
| 163 | try { |
| 164 | // process.kill throws an exception if the process doesn't exist. |
| 165 | process.kill(this.parentPid, 0) |
| 166 | } catch (_) { |
| 167 | // Consider this an error since it should have been able to clean up |
| 168 | // the child process unless it was forcefully killed. |
| 169 | this.logger.error(`parent process ${parentPid} died`) |
| 170 | this._onDispose.emit(undefined) |
| 171 | } |
| 172 | }, 5000) |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Initiate the handshake and wait for a response from the parent. |