1 // vim:ts=4:sw=4:expandtab
14 * Checks if the PID in path is still valid by sending signal 0 (does not do
15 * anything). kill() will return ESRCH if the process does not exist and 0 or
16 * EPERM (depending on the uid) if it exists.
18 * If multiple files match the glob pattern, all of them will be checked until
19 * the first running process is found.
22 bool process_runs(const char *path) {
23 static char pidbuf[16];
24 static glob_t globbuf;
25 memset(pidbuf, 0, sizeof(pidbuf));
27 if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
28 die("glob() failed\n");
29 if (globbuf.gl_pathc == 0) {
30 /* No glob matches, the specified path does not contain a wildcard. */
32 if (!slurp(path, pidbuf, sizeof(pidbuf)))
34 return (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM);
36 for (size_t i = 0; i < globbuf.gl_pathc; i++) {
37 if (!slurp(globbuf.gl_pathv[i], pidbuf, sizeof(pidbuf))) {
41 if (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM) {