Toolhelp is the documented way to learn one's own parent PID on Windows; * the PEB value is not exposed through any public API. Returns 0 when the * lookup itself fails; callers treat that as "no parent signal available". */
| 598 | * the PEB value is not exposed through any public API. Returns 0 when the |
| 599 | * lookup itself fails; callers treat that as "no parent signal available". */ |
| 600 | static DWORD win_parent_pid_from_snapshot(void) { |
| 601 | DWORD parent_pid = 0; |
| 602 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
| 603 | if (snapshot == INVALID_HANDLE_VALUE) { |
| 604 | return 0; |
| 605 | } |
| 606 | PROCESSENTRY32W entry; |
| 607 | ZeroMemory(&entry, sizeof(entry)); |
| 608 | entry.dwSize = sizeof(entry); |
| 609 | DWORD self_pid = GetCurrentProcessId(); |
| 610 | if (Process32FirstW(snapshot, &entry)) { |
| 611 | do { |
| 612 | if (entry.th32ProcessID == self_pid) { |
| 613 | parent_pid = entry.th32ParentProcessID; |
| 614 | break; |
| 615 | } |
| 616 | } while (Process32NextW(snapshot, &entry)); |
| 617 | } |
| 618 | CloseHandle(snapshot); |
| 619 | return parent_pid; |
| 620 | } |
| 621 | |
| 622 | static bool client_start_parent_watchdog(DWORD initial_ppid) { |
| 623 | /* Mirrors the POSIX initial_ppid <= 1 bail-out: when no trustworthy parent |