1 #include <pxp-agent/util/process.hpp>
2 
3 #include <signal.h>
4 #include <errno.h>
5 #include <unistd.h>         // getpid()
6 
7 namespace PXPAgent {
8 namespace Util {
9 
10 // Checks the PID by sending NULL SIGNAL WITH kill().
11 // NB: does not consider recycled PIDs nor zombie processes.
processExists(int pid)12 bool processExists(int pid) {
13     if (kill(pid, 0)) {
14         switch (errno) {
15             case ESRCH:
16                 return false;
17             case EPERM:
18                 // Process exists, but we can't signal to it
19                 return true;
20             default:
21                 // Unexpected
22                 return false;
23         }
24     }
25 
26     return true;
27 }
28 
getPid()29 int getPid() {
30     return getpid();
31 }
32 
33 }  // namespace Util
34 }  // namespace PXPAgent
35