MCPcopy Create free account
hub / github.com/containers/common / AddPid

Method AddPid

pkg/cgroups/cgroups.go:587–620  ·  view source on GitHub ↗

AddPid moves the specified pid to the cgroup

(pid int)

Source from the content-addressed store, hash-verified

585
586// AddPid moves the specified pid to the cgroup
587func (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
623func (c *CgroupControl) Stat() (*Metrics, error) {

Callers

nothing calls this directly

Calls 1

getCgroupv1PathMethod · 0.95

Tested by

no test coverage detected