From b2d49eb6ca4e20e89f3628e2cd7c9a3423c2ee28 Mon Sep 17 00:00:00 2001 From: Fancy Zhang Date: Tue, 11 Aug 2020 19:19:27 +0800 Subject: [PATCH] ignore process live too short error If cgroup is empty, then the process is not exsit any more. So can be ignored. --- src/cgroup_attach.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cgroup_attach.cpp b/src/cgroup_attach.cpp index 13c49ca..3bf6b6a 100644 --- a/src/cgroup_attach.cpp +++ b/src/cgroup_attach.cpp @@ -52,7 +52,11 @@ int attach(const string pid, const string cgroup_target) { // return_error } - if (getCgroup(pid) == cgroup_target) { + string cg; + + cg = getCgroup(pid); + if (cg.empty()) return_success; + if (cg == cgroup_target) { debug("%s already in %s", pid.c_str(), cgroup_target.c_str()); return_success; } @@ -62,7 +66,9 @@ int attach(const string pid, const string cgroup_target) { // wait for small period and check again this_thread::sleep_for(std::chrono::milliseconds(100)); - if (getCgroup(pid) != cgroup_target && write2procs(pid, cgroup_target_procs) != 0) + cg = getCgroup(pid); + if (cg.empty()) return_success; + if (cg != cgroup_target && write2procs(pid, cgroup_target_procs) != 0) return_error; return_success; } @@ -78,7 +84,7 @@ int write2procs(string pid, string procspath) { // maybe there some write error, for example process pid may not exist if (!procs) { - error("write %s to %s failed, maybe process %s not exist", pid.c_str(), + error("write %s to %s failed, maybe process %s live too short", pid.c_str(), procspath.c_str(), pid.c_str()); return_error; }