processgroup: change the polling interval for killProcessGroup()
to make the function faster on average. Since killing a process
takes about 40-60ms on a recent device, the previous logic tends
to sleep too long. This CL does not significantly change the total
timeout (old code: 204ms, new code: 200ms).
Bug: 21813611
Change-Id: Ica44b2437ccccaebadcf585d7a09d993ce71a499
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index a80965f..ad0500d 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -252,14 +252,15 @@
int killProcessGroup(uid_t uid, int initialPid, int signal)
{
int processes;
- int sleep_us = 100;
+ const int sleep_us = 5 * 1000; // 5ms
int64_t startTime = android::uptimeMillis();
+ int retry = 40;
while ((processes = killProcessGroupOnce(uid, initialPid, signal)) > 0) {
SLOGV("killed %d processes for processgroup %d\n", processes, initialPid);
- if (sleep_us < 128000) {
+ if (retry > 0) {
usleep(sleep_us);
- sleep_us *= 2;
+ --retry;
} else {
SLOGE("failed to kill %d processes for processgroup %d\n",
processes, initialPid);