Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant size space tracking of pids #1762

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions client/driver/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,32 +773,34 @@ func (e *UniversalExecutor) scanPids(parentPid int, allPids []ps.Process) (map[i
processFamily := make(map[int]struct{})
processFamily[parentPid] = struct{}{}

// A buffer for holding pids which haven't matched with any parent pid
var pidsRemaining []ps.Process
// A mapping of pids to their parent pids. It is used to build the process
// tree of the executing task
pidsRemaining := make(map[int]int, len(allPids))
for _, pid := range allPids {
pidsRemaining[pid.Pid()] = pid.PPid()
}

for {
// flag to indicate if we have found a match
foundNewPid := false

for _, pid := range allPids {
_, childPid := processFamily[pid.PPid()]
for pid, ppid := range pidsRemaining {
_, childPid := processFamily[ppid]

// checking if the pid is a child of any of the parents
if childPid {
processFamily[pid.Pid()] = struct{}{}
processFamily[pid] = struct{}{}
delete(pidsRemaining, pid)
foundNewPid = true
} else {
// if it is not, then we add the pid to the buffer
pidsRemaining = append(pidsRemaining, pid)
}
// scan only the pids which are left in the buffer
allPids = pidsRemaining
}

// not scanning anymore if we couldn't find a single match
if !foundNewPid {
break
}
}

res := make(map[int]*nomadPid)
for pid := range processFamily {
np := nomadPid{
Expand Down