Skip to content

Commit 6659093

Browse files
committed
cgroup v1: implement AddProc()
This implements AddProc() for cgroups v1 to make the API a closer match with the cgroupsv2 API. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 616d434 commit 6659093

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

cgroup.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ func (c *cgroup) Add(process Process) error {
162162
return c.add(process)
163163
}
164164

165+
// AddProc moves the provided process id into the new cgroup
166+
func (c *cgroup) AddProc(pid uint64) error {
167+
c.mu.Lock()
168+
defer c.mu.Unlock()
169+
if c.err != nil {
170+
return c.err
171+
}
172+
return c.Add(Process{Pid: int(pid)})
173+
}
174+
165175
func (c *cgroup) add(process Process) error {
166176
for _, s := range pathers(c.subsystems) {
167177
p, err := c.path(s.Name())

control.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type Cgroup interface {
6161
New(string, *specs.LinuxResources) (Cgroup, error)
6262
// Add adds a process to the cgroup (cgroup.procs)
6363
Add(Process) error
64+
// AddProc adds the process with the given id to the cgroup (cgroup.procs)
65+
AddProc(pid uint64) error
6466
// AddTask adds a process to the cgroup (tasks)
6567
AddTask(Process) error
6668
// Delete removes the cgroup as a whole

0 commit comments

Comments
 (0)