如何解决如何将子 shell 添加到 cgroup? 子外壳在休眠时表现不同其实第一个适合我,我该怎么办?
子外壳在休眠时表现不同
- 创建父 cgroup 和子 cgroup
pg := cgroups.New(
cgroups.V1,cgroups.StaticPath("test-panda"),...,)
cg := pg.New(
"panda-plugins-test.slice",&specs.LinuxResources{
CPU: &specs.LinuxCPU{
Quota: "a,Period: &period,},Memory: &specs.LinuxMemory{
Limit: &mem,DisableOOMKiller: &c.disableoom,)
- 创建cmd进程并将pid添加到子cgroup
cmd := exec.Command(p.opts.Path,p.opts.Args...)
cmd.Path = "/tmp/plugins/test.sh"
cmd.Dir = "/tmp/plugins/"
pid := cmd.Process.Pid
cg.Add(cgroups.Process{Pid: pid})
- 执行并等待cmd进程
go func() {
defer func() {
close(ch)
p.exit()
}()
wait := func() (int,error) {
err := p.cmd.Wait()
if err != nil {
exitErr,ok := err.(*exec.ExitError)
if !ok {
return -1,err
}
status,ok := exitErr.Sys().(syscall.WaitStatus)
if !ok {
return -1,err
}
return status.ExitStatus(),err
}
return 0,nil
}
p.exitCode,p.exitErr = wait()
p.log.Infof("process %s exited with %d | %v",p.opts.Name,p.exitCode,p.exitErr)
}()
运行这段代码
[root@st1-tool-web-3] /tmp/test$ ./cgroup_demo
-
期间查看 cgroup
4.1 当 test.sh 内容为
#!/bin/bash sleep 5 /bin/bash ./a.sh
查看 cgroup 是
[root@st1-tool-web-3] /home/ansible$ systemd-cgls ├─1 /usr/lib/systemd/systemd --system --deserialize 21 ├─test-panda │ ├─28869 ./cgroup_demo │ └─panda-plugins-test.slice │ ├─28874 /bin/bash /tmp/plugins/test.sh │ ├─28894 /bin/bash ./a.sh │ └─28895 sleep 20
4.2 当 test.sh 内容为
#!/bin/bash /bin/bash ./a.sh
cgroup 是
[root@st1-tool-web-3] /home/ansible$ systemd-cgls ├─1 /usr/lib/systemd/systemd --system --deserialize 21 ├─test-panda │ ├─22620 ./cgroup_demo │ ├─22626 /bin/bash ./a.sh │ ├─22628 sleep 20 │ └─panda-plugins-test.slice │ └─22625 /bin/bash /tmp/plugins/test.sh
其实第一个适合我,我该怎么办?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。