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

Function forEachRunningProcess

src/envmodule.cpp:478–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476
477template <class F>
478void forEachRunningProcess(F&& f)
479{
480 HandlePtr snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
481
482 if (snapshot.get() == INVALID_HANDLE_VALUE) {
483 const auto e = GetLastError();
484 log::error("CreateToolhelp32Snapshot() failed, {}", formatSystemMessage(e));
485 return;
486 }
487
488 PROCESSENTRY32 entry = {};
489 entry.dwSize = sizeof(entry);
490
491 // first process, this shouldn't fail because there's at least one process
492 // running
493 if (!Process32First(snapshot.get(), &entry)) {
494 const auto e = GetLastError();
495 log::error("Process32First() failed, {}", formatSystemMessage(e));
496 return;
497 }
498
499 for (;;) {
500 if (!f(entry)) {
501 break;
502 }
503
504 // next process
505 if (!Process32Next(snapshot.get(), &entry)) {
506 const auto e = GetLastError();
507
508 // no more processes is not an error
509 if (e != ERROR_NO_MORE_FILES)
510 log::error("Process32Next() failed, {}", formatSystemMessage(e));
511
512 break;
513 }
514 }
515}
516
517std::vector<Process> getRunningProcesses()
518{

Callers 3

getRunningProcessesFunction · 0.85
getProcessTreeFromJobFunction · 0.85
getProcessParentIDFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected