+static int realloc_pid_list(pid_t **pid_list, unsigned int *pid_list_size)
+{
+ pid_t *new_pid_list;
+ unsigned int new_pid_list_size = 2 * *pid_list_size;
+
+ new_pid_list = realloc(*pid_list,
+ new_pid_list_size * sizeof(pid_t));
+ if (!*new_pid_list) {
+ return -1;
+ }
+
+ *pid_list = new_pid_list;
+ *pid_list_size = new_pid_list_size;
+
+ return 0;
+}
+
+static int get_pids_in_dir(DIR *dir, pid_t **pid_list,
+ unsigned int *pid_list_index,