github.com/runcom/containerd@v0.0.0-20160708090337-9bff9f934c0d/supervisor/sort.go (about)

     1  package supervisor
     2  
     3  import (
     4  	"sort"
     5  
     6  	"github.com/docker/containerd/runtime"
     7  )
     8  
     9  func sortProcesses(p []runtime.Process) {
    10  	sort.Sort(&processSorter{p})
    11  }
    12  
    13  type processSorter struct {
    14  	processes []runtime.Process
    15  }
    16  
    17  func (s *processSorter) Len() int {
    18  	return len(s.processes)
    19  }
    20  
    21  func (s *processSorter) Swap(i, j int) {
    22  	s.processes[i], s.processes[j] = s.processes[j], s.processes[i]
    23  }
    24  
    25  func (s *processSorter) Less(i, j int) bool {
    26  	return s.processes[j].ID() == "init"
    27  }