diff --git a/bazaar/SysInfo/SysInfo.cpp b/bazaar/SysInfo/SysInfo.cpp index ec813f766..92a6018f3 100644 --- a/bazaar/SysInfo/SysInfo.cpp +++ b/bazaar/SysInfo/SysInfo.cpp @@ -914,6 +914,41 @@ Array GetProcessList() return ret; } +Array GetChildProcessList(int64 processID) +{ + PROCESSENTRY32 proc; + Array child, all, parents; + HANDLE hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (hSnap == INVALID_HANDLE_VALUE) + return child; + proc.dwSize = sizeof(proc); + long f = Process32First(hSnap, &proc); + while (f) { + all << proc.th32ProcessID; + parents << proc.th32ParentProcessID; + f = Process32Next(hSnap, &proc); + } + CloseHandle(hSnap); + child << processID; + int init = 0; + while (true) { + int count = child.GetCount(); + if (init >= count) + break; + for (int cid = init; cid < count; ++cid) { + for (int i = 0; i < all.GetCount(); ++i) { + if (all[i] == child[cid]) + continue; + else if (parents[i] == child[cid]) + child << parents[i]; + } + } + init = count; + } + child.Remove(0); + return child; +} + String GetProcessName(int64 processID) { WCHAR szProcessName[MAX_PATH]; diff --git a/bazaar/SysInfo/SysInfo.h b/bazaar/SysInfo/SysInfo.h index 533c16b23..bcf8dd2d6 100644 --- a/bazaar/SysInfo/SysInfo.h +++ b/bazaar/SysInfo/SysInfo.h @@ -74,6 +74,9 @@ int Window_GetStatus(int64 windowId); ///////////////////////////////////////////////////////////////////// // Process list bool GetProcessList(Upp::Array &pid, Upp::Array &pNames); +#if defined(PLATFORM_WIN32) +Upp::Array GetChildProcessList(int64 processID); +#endif Upp::Array GetProcessList(); String GetProcessName(int64 pid); String GetProcessFileName(int64 processID);