@@ -218,6 +218,8 @@ UPDATE: This is done now!!
218218 DWORD parentPid = 0 ;
219219 HANDLE hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0 );
220220 if (hSnapshot == INVALID_HANDLE_VALUE) return ;
221+ DWORD targetpid = pid; // the function already passes pid into us, but
222+ // just to be safe that pid doesn't get overwritten in the loop below
221223 std::string exeName = " Unknown/Dead Process" ;
222224 std::vector<std::string> exeNames;
223225 std::vector<ULONGLONG> exeTimes; // sorry for the crap code but idk how to make multidimensional arrays yet 😭😭😭
@@ -258,7 +260,40 @@ UPDATE: This is done now!!
258260
259261 if (!found) break ;
260262 }
261- CloseHandle (hSnapshot);
263+ // we're close... but not done yet. we need to find the CHILDREN of the process now.
264+ // We can create another loop, but this time going downwards, checking if a process
265+ // tells us that our target pid is it's parent. This time, we don't have to worry about
266+ // Checking if the parent is alive, because, well, since the target IS the parent,
267+ // it must be alive.
268+ if (Process32First (hSnapshot, &pe32)) {
269+ do {
270+ if (pe32.th32ProcessID == pid) {
271+ // this time, our target pid is already stored at the very top of our list.
272+ // this means we don't have to add target pid stuff.
273+ // TODO: (for future optimization) we should probably move this before the
274+ // the previous loop, since emplacing to the front requires shifting the entire list
275+ // and therefore is inefficient, robbing us of a couple milliseconds of precious cpu time :(
276+
277+ if (pe32.th32ParentProcessID == targetpid) {
278+ exeName = WideToString (pe32.szExeFile ); // this stores the name of our pid we're looking at in a var
279+ exeNames.emplace (exeNames.begin (), exeName); // this adds this to the front of the list
280+ // in this case, we are adding stuff to the front of the list, since we're looking at children
281+ // you might've noticed this doesn't have an emplace_front() like emplace_back() since
282+ // it's inefficient and the creators of the vector lib didn't do it
283+ ULONGLONG parentTime = GetProcessCreationTime (pe32);
284+
285+ }
286+
287+
288+ found = true ;
289+ break ;
290+ }
291+ } while (Process32Next (hSnapshot, &pe32));
292+
293+ }
294+
295+
296+ CloseHandle (hSnapshot); // we're only closing the handle until we finish messing with the snapshot
262297 // phew thankfully we're done with that mess
263298 // now we need to reverse all the vector lists we made so
264299 // that the ancestry tree is correctly diisplayed from root to children like witr
0 commit comments