+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <libgen.h>
return ret > 0 ? 0 : -1;
}
+static int pid_is_ok(int pid)
+{
+ struct stat statt;
+ char path[64];
+
+ snprintf(path, sizeof(path), "/proc/%d/", pid);
+
+ if (stat(path, &statt))
+ return 0;
+
+ return pid;
+}
+
+/*
+ * Test whether a pid string number exists in the system as a pid
+ * number
+ */
+int pidstr_is_ok(const char *str)
+{
+ int i, pid;
+
+ /* Test that it is all digits */
+ for (i = 0; i < strlen(str); i++)
+ if (str[i] < '0' || str[i] > '9')
+ return 0;
+
+ pid = atoi(str);
+
+ return pid_is_ok(pid);
+}