AddPid moves the specified pid to the cgroup
(pid int)
| 585 | |
| 586 | // AddPid moves the specified pid to the cgroup |
| 587 | func (c *CgroupControl) AddPid(pid int) error { |
| 588 | pidString := []byte(fmt.Sprintf("%d\n", pid)) |
| 589 | |
| 590 | if c.cgroup2 { |
| 591 | p := filepath.Join(cgroupRoot, c.path, "cgroup.procs") |
| 592 | if err := ioutil.WriteFile(p, pidString, 0644); err != nil { |
| 593 | return errors.Wrapf(err, "write %s", p) |
| 594 | } |
| 595 | return nil |
| 596 | } |
| 597 | |
| 598 | names := make([]string, 0, len(handlers)) |
| 599 | for n := range handlers { |
| 600 | names = append(names, n) |
| 601 | } |
| 602 | |
| 603 | for _, c := range c.additionalControllers { |
| 604 | if !c.symlink { |
| 605 | names = append(names, c.name) |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | for _, n := range names { |
| 610 | // If we aren't using cgroup2, we won't write correctly to unified hierarchy |
| 611 | if !c.cgroup2 && n == "unified" { |
| 612 | continue |
| 613 | } |
| 614 | p := filepath.Join(c.getCgroupv1Path(n), "tasks") |
| 615 | if err := ioutil.WriteFile(p, pidString, 0644); err != nil { |
| 616 | return errors.Wrapf(err, "write %s", p) |
| 617 | } |
| 618 | } |
| 619 | return nil |
| 620 | } |
| 621 | |
| 622 | // Stat returns usage statistics for the cgroup |
| 623 | func (c *CgroupControl) Stat() (*Metrics, error) { |
nothing calls this directly
no test coverage detected