12 /* TODO: correctly check for *BSD */
13 #include <sys/param.h>
14 #include <sys/sysctl.h>
15 #include <sys/resource.h>
21 * Checks if the PID in path is still valid by checking:
22 * (Linux) if /proc/<pid> exists
23 * (NetBSD) if sysctl returns process infos for this pid
26 bool process_runs(const char *path) {
28 static glob_t globbuf;
30 memset(pidbuf, 0, sizeof(pidbuf));
32 if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
33 die("glob() failed\n");
34 fd = open((globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path), O_RDONLY);
38 (void)read(fd, pidbuf, sizeof(pidbuf));
44 (void)snprintf(procbuf, sizeof(procbuf), "/proc/%ld", strtol(pidbuf, NULL, 10));
45 return (stat(procbuf, &statbuf) >= 0);
47 /* TODO: correctly check for NetBSD. Evaluate if this runs on OpenBSD/FreeBSD */
48 struct kinfo_proc info;
49 size_t length = sizeof(struct kinfo_proc);
50 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, strtol(pidbuf, NULL, 10) };
51 if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)