libprocessgroup: Add sendSignalToProcessGroup
Add a function which sends signals to all members of a process group, but does not wait for the processes to exit, or for the associated cgroup to be removed. Bug: 274646058 Ignore-AOSP-First: Dependency of ActivityManager change which developed on interal git_master Test: Force-stop of chrome with 15 tabs completes ~500ms faster Test: Full Play store update causes no ANR (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d87b6018d25cbbd33b345dc58c634718bf5d0def) Merged-In: I37dbdecb3394101abbee8495e71f6912b3c031f5 Change-Id: I37dbdecb3394101abbee8495e71f6912b3c031f5 NOTE FOR REVIEWERS - original patch and result patch are not identical. PLEASE REVIEW CAREFULLY. Diffs between the patches: 37,6 +537,15 @@ return KillProcessGroup(uid, initialPid, signal, 0 /*retries*/, max_processes); } +int sendSignalToProcessGroup(uid_t uid, int initialPid, int signal) { + std::string hierarchy_root_path; + if (CgroupsAvailable()) { + CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &hierarchy_root_path); + } + const char* cgroup = hierarchy_root_path.c_str(); + return DoKillProcessGroupOnce(cgroup, uid, initialPid, signal); +} + static int createProcessGroupInternal(uid_t uid, int initialPid, std::string cgroup, bool activate_controllers) { auto uid_path = ConvertUidToPath(cgroup.c_str(), uid); Original patch: From d87b6018 Mon Sep 17 00:00:00 2001 From: T.J. Mercier <tjmercier@google.com> Date: Tue, 04 Apr 2023 18:41:13 +0000 Subject: [PATCH] libprocessgroup: Add sendSignalToProcessGroup Add a function which sends signals to all members of a process group, but does not wait for the processes to exit, or for the associated cgroup to be removed. Bug: 274646058 Ignore-AOSP-First: Dependency of ActivityManager change which developed on interal git_master Test: Force-stop of chrome with 15 tabs completes ~500ms faster Test: Full Play store update causes no ANR Change-Id: I37dbdecb3394101abbee8495e71f6912b3c031f5 --- diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index 8fa9fd5..48bc0b7 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -76,6 +76,11 @@ // that it only returns 0 in the case that the cgroup exists and it contains no processes. int killProcessGroupOnce(uid_t uid, int initialPid, int signal, int* max_processes = nullptr); +// Sends the provided signal to all members of a process group, but does not wait for processes to +// exit, or for the cgroup to be removed. Callers should also ensure that killProcessGroup is called +// later to ensure the cgroup is fully removed, otherwise system resources may leak. +int sendSignalToProcessGroup(uid_t uid, int initialPid, int signal); + int createProcessGroup(uid_t uid, int initialPid, bool memControl = false); // Set various properties of a process group. For these functions to work, the process group must Change-Id: Ie479348dee8e8092b1959927a1143009632d3914
Loading
Please register or sign in to comment