+/*
+ * Checks if the PID in path is still valid by checking if /proc/<pid> exists
+ *
+ */
+bool process_runs(const char *path) {
+ char pidbuf[512],
+ procbuf[512];
+ static glob_t globbuf;
+ struct stat statbuf;
+
+ if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
+ die("glob() failed");
+ const char *real_path = (globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
+ int fd = open(real_path, O_RDONLY);
+ globfree(&globbuf);
+ if (fd < 0)
+ return false;
+ read(fd, pidbuf, sizeof(pidbuf));
+ close(fd);
+ sprintf(procbuf, "/proc/%s", pidbuf);
+ return (stat(procbuf, &statbuf) >= 0);
+}