MCPcopy Create free account
hub / github.com/dobin/RedEdr / CleanupStaleProcesses

Method CleanupStaleProcesses

RedEdrShared/process_resolver.cpp:268–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266
267
268void ProcessResolver::CleanupStaleProcesses() {
269 LOG_A(LOG_INFO, "ProcessResolver: Starting cleanup of stale processes");
270
271 std::vector<DWORD> pidsToRemove;
272 size_t totalProcesses = 0;
273
274 {
275 std::lock_guard<std::mutex> lock(cache_mutex);
276 totalProcesses = cache.size();
277
278 for (const auto& pair : cache) {
279 DWORD pid = pair.first;
280
281 // Check if process is still alive
282 if (!IsProcessAlive(pid)) {
283 pidsToRemove.push_back(pid);
284 }
285 }
286 }
287
288 // Remove stale processes (outside the lock to avoid holding it too long)
289 for (DWORD pid : pidsToRemove) {
290 removeObject(pid);
291 }
292
293 if (!pidsToRemove.empty()) {
294 LOG_A(LOG_INFO, "ProcessResolver: Cleaned up %zu stale processes (was: %zu, now: %zu)",
295 pidsToRemove.size(), totalProcesses, GetCacheCount());
296 } else {
297 LOG_A(LOG_DEBUG, "ProcessResolver: No stale processes found during cleanup");
298 }
299}
300
301
302bool ProcessResolver::IsProcessAlive(DWORD pid) {

Callers

nothing calls this directly

Calls 3

emptyMethod · 0.80
LOG_AFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected