From fec47ada947bd60468b1ba1b20f4ec04182c3955 Mon Sep 17 00:00:00 2001 From: iritb Date: Wed, 8 Jan 2025 17:00:10 +0200 Subject: [PATCH] added a comment --- ProcessTree.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ProcessTree.cpp b/ProcessTree.cpp index 7774b42..c2dc49e 100644 --- a/ProcessTree.cpp +++ b/ProcessTree.cpp @@ -427,8 +427,21 @@ std::shared_ptr ProcessTree::AddProcess(enum ProcessTreeSource ApplyFlags(process); _processes[pid] = process; } - - // Call ReadProcEntry to ensure container ID is set if it's still empty + + // The purpose of extracting the container ID from cgroup is to accurately identify + // the container in which a process is running. This is particularly important for + // monitoring and logging purposes in containerized environments, where applications + // are packaged and run in containers. By testing the extraction logic with various + // cgroup formats, we aim to ensure that the container ID is correctly identified in + // all scenarios. + // This method complements the existing logic that extracts the container ID from the + // command line arguments by providing an additional, more reliable source of information. + // This is especially relevant when the container ID is not found through the existing + // logic, which can happen when there is no parent process or when the parent process + // does not have the container ID set. This situation can occur in various scenarios, + // such as when a process is the root process of a container or when the process is + // started by a web service or another system service that does not pass the container + // ID through the command line arguments. if (process->_containerid.empty()) { auto p_temp = ReadProcEntry(pid); if (p_temp) {