MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / getProcessTreeFromJob

Function getProcessTreeFromJob

src/envmodule.cpp:634–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

632}
633
634Process getProcessTreeFromJob(HANDLE h)
635{
636 const auto ids = processesInJob(h);
637 if (ids.empty()) {
638 return {};
639 }
640
641 std::vector<Process> ps;
642
643 forEachRunningProcess([&](auto&& entry) {
644 for (auto&& id : ids) {
645 if (entry.th32ProcessID == id) {
646 ps.push_back(Process(entry.th32ProcessID, entry.th32ParentProcessID,
647 QString::fromStdWString(entry.szExeFile)));
648
649 break;
650 }
651 }
652
653 return true;
654 });
655
656 Process root;
657
658 {
659 // getting processes whose parent is not in the list
660 for (auto&& possibleRoot : ps) {
661 const auto ppid = possibleRoot.ppid();
662 bool found = false;
663
664 for (auto&& p : ps) {
665 if (p.pid() == ppid) {
666 found = true;
667 break;
668 }
669 }
670
671 if (!found) {
672 // this is a root process
673 root.addChild(possibleRoot);
674 }
675 }
676
677 // removing root processes from the list
678 auto newEnd = std::remove_if(ps.begin(), ps.end(), [&](auto&& p) {
679 for (auto&& rp : root.children()) {
680 if (rp.pid() == p.pid()) {
681 return true;
682 }
683 }
684
685 return false;
686 });
687
688 ps.erase(newEnd, ps.end());
689 }
690
691 // at this point, `processes` should only contain processes that are direct

Callers 1

getProcessTreeFunction · 0.85

Calls 11

processesInJobFunction · 0.85
forEachRunningProcessFunction · 0.85
findChildProcessesFunction · 0.85
ppidMethod · 0.80
addChildMethod · 0.80
childrenMethod · 0.80
ProcessClass · 0.70
emptyMethod · 0.45
pidMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected