| 262 | } |
| 263 | |
| 264 | int Process::get_exit_status() noexcept { |
| 265 | if(data.id == 0) |
| 266 | return -1; |
| 267 | |
| 268 | if(!data.handle) |
| 269 | return data.exit_status; |
| 270 | |
| 271 | WaitForSingleObject(data.handle, INFINITE); |
| 272 | |
| 273 | DWORD exit_status; |
| 274 | if(!GetExitCodeProcess(data.handle, &exit_status)) |
| 275 | data.exit_status = -1; // Store exit status for future calls |
| 276 | else |
| 277 | data.exit_status = static_cast<int>(exit_status); // Store exit status for future calls |
| 278 | |
| 279 | { |
| 280 | std::lock_guard<std::mutex> lock(close_mutex); |
| 281 | CloseHandle(data.handle); |
| 282 | data.handle = nullptr; |
| 283 | closed = true; |
| 284 | } |
| 285 | close_fds(); |
| 286 | |
| 287 | return data.exit_status; |
| 288 | } |
| 289 | |
| 290 | bool Process::try_get_exit_status(int &exit_status) noexcept { |
| 291 | if(data.id == 0) { |