Verify if pid actually killed for processes with open files

Its possible for vold to read a pid from procfs, the pid is killed
externally and then vold tries to kill it. In this scenario, we sleep
for 5s without needing it. Verify the return value from the kill syscall
and validate that the pid was killed, if the pid didn't exist at the
moment of the kill call, then don't count the pid as being killed.

Test: Boots successfully
Bug: 307801020
Change-Id: Ie127108b85be7249cf8b2881f4917d653d032186
diff --git a/Process.cpp b/Process.cpp
index c1d55ee..426a425 100644
--- a/Process.cpp
+++ b/Process.cpp
@@ -173,6 +173,7 @@
             }
         }
     }
+    int totalKilledPids = pids.size();
     if (signal != 0) {
         for (const auto& pid : pids) {
             std::string comm;
@@ -184,10 +185,17 @@
 
             LOG(WARNING) << "Sending " << strsignal(signal) << " to pid " << pid << " (" << comm
                          << ", " << exe << ")";
-            kill(pid, signal);
+            if (kill(pid, signal) < 0) {
+                if (errno == ESRCH) {
+                    totalKilledPids--;
+                    LOG(WARNING) << "The target pid " << pid << " was already killed";
+                    continue;
+                }
+                LOG(ERROR) << "Unable to send signal " << strsignal(signal) << " to pid " << pid;
+            }
         }
     }
-    return pids.size();
+    return totalKilledPids;
 }
 
 }  // namespace vold