Skip to content

Commit

Permalink
Merge pull request #440 from kubescape/feature/support-fork-exec
Browse files Browse the repository at this point in the history
Adding support for fork exec to get real process details
  • Loading branch information
amitschendel authored Dec 19, 2024
2 parents 9926c89 + ecd15b7 commit c31c78d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/processmanager/v1/process_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
const (
cleanupInterval = 1 * time.Minute
maxTreeDepth = 50
runCCommPrefix = "runc:["
)

type ProcessManager struct {
Expand Down Expand Up @@ -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.
// 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
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
}

Expand Down

0 comments on commit c31c78d

Please sign in to comment.