From ba8885d1020374b418e2a776dea5946c1beabe37 Mon Sep 17 00:00:00 2001 From: koldo Date: Wed, 8 Jul 2015 05:49:27 +0000 Subject: [PATCH] SysInfo: Added new functions git-svn-id: svn://ultimatepp.org/upp/trunk@8644 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/SysInfo/SysInfo.cpp | 35 +++++++++++++++++++++++++++++++++++ bazaar/SysInfo/SysInfo.h | 3 +++ 2 files changed, 38 insertions(+) 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);