Skip to content

Commit

Permalink
Merge pull request #1762 from hashicorp/b-scan-pids
Browse files Browse the repository at this point in the history
Constant size space tracking of pids
  • Loading branch information
dadgar committed Sep 28, 2016
2 parents 95af837 + 42c4346 commit 2143ee1
Showing 1 changed file with 12 additions and 10 deletions.
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

0 comments on commit 2143ee1

Please sign in to comment.