From d5bf6a3c7a876c24a314f1634cf26eaee8a2fd49 Mon Sep 17 00:00:00 2001 From: Amit Schendel Date: Wed, 18 Dec 2024 21:09:07 +0000 Subject: [PATCH 1/2] Adding support for fork exec to get real process details Signed-off-by: Ubuntu --- pkg/processmanager/v1/process_manager.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/processmanager/v1/process_manager.go b/pkg/processmanager/v1/process_manager.go index 9d59c7c4..b5e4ce1e 100644 --- a/pkg/processmanager/v1/process_manager.go +++ b/pkg/processmanager/v1/process_manager.go @@ -20,6 +20,7 @@ import ( const ( cleanupInterval = 1 * time.Minute maxTreeDepth = 50 + runCCommPrefix = "runc:[" ) type ProcessManager struct { @@ -275,6 +276,20 @@ func (p *ProcessManager) GetProcessTreeForPID(containerID string, pid int) (apit } } + // If the process is runc, try to fetch the real process info. + // Intentiaoanlly we are doing this only once the process is asked for to avoid unnecessary calls to /proc and give time for the process to be created. + if strings.HasPrefix(result.Comm, runCCommPrefix) { + if process, err := p.getProcessFromProc(int(result.PID)); err == nil { + childerns := result.Children + upperLayer := result.UpperLayer + result = process + result.Children = childerns + result.UpperLayer = upperLayer + // Update the process in the tree + p.processTree.Set(result.PID, result) + } + } + return result, nil } From ecd15b72a198e0f6f0d3347e1bf322bf3a83562b Mon Sep 17 00:00:00 2001 From: Amit Schendel Date: Wed, 18 Dec 2024 21:10:49 +0000 Subject: [PATCH 2/2] Fixing typo Signed-off-by: Amit Schendel --- pkg/processmanager/v1/process_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/processmanager/v1/process_manager.go b/pkg/processmanager/v1/process_manager.go index b5e4ce1e..0e101a2c 100644 --- a/pkg/processmanager/v1/process_manager.go +++ b/pkg/processmanager/v1/process_manager.go @@ -277,7 +277,7 @@ func (p *ProcessManager) GetProcessTreeForPID(containerID string, pid int) (apit } // If the process is runc, try to fetch the real process info. - // Intentiaoanlly we are doing this only once the process is asked for to avoid unnecessary calls to /proc and give time for the process to be created. + // Intentionally we are doing this only once the process is asked for to avoid unnecessary calls to /proc and give time for the process to be created. if strings.HasPrefix(result.Comm, runCCommPrefix) { if process, err := p.getProcessFromProc(int(result.PID)); err == nil { childerns := result.Children