| 361 | void Run(); |
| 362 | |
| 363 | inline void Terminate(int signal) { |
| 364 | if (!!Pid && (ExecutionStatus.load(std::memory_order_acquire) == SHELL_RUNNING)) { |
| 365 | #if defined(_unix_) |
| 366 | bool ok = kill(Options_.DetachSession ? -1 * Pid : Pid, signal) == 0; |
| 367 | if (!ok && (errno == ESRCH) && Options_.DetachSession) { |
| 368 | // this could fail when called before child proc completes setsid(). |
| 369 | ok = kill(Pid, signal) == 0; |
| 370 | kill(-Pid, signal); // between a failed kill(-Pid) and a successful kill(Pid) a grandchild could have been spawned |
| 371 | } |
| 372 | #else |
| 373 | Y_UNUSED(signal); |
| 374 | bool ok = TerminateProcess(Pid, 1 /* exit code */); |
| 375 | #endif |
| 376 | if (!ok) { |
| 377 | ythrow TSystemError() << "cannot terminate " << Pid; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | inline void Wait() { |
| 383 | if (WatchThread) { |
no test coverage detected