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