MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / win_parent_pid_from_snapshot

Function win_parent_pid_from_snapshot

src/main.c:600–620  ·  view source on GitHub ↗

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". */

Source from the content-addressed store, hash-verified

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". */
600static 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
622static bool client_start_parent_watchdog(DWORD initial_ppid) {
623 /* Mirrors the POSIX initial_ppid <= 1 bail-out: when no trustworthy parent

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected