+void tids_sweep_procs(TIDS_INSTANCE *tids)
+{
+ guint ii;
+ pid_t pid;
+ int status;
+
+ /* loop backwards over the array so we can remove elements as we go */
+ for (ii=tids->pids->len; ii > 0; ii--) {
+ /* ii-1 is the current index */
+ pid = g_array_index(tids->pids, pid_t, ii-1);
+ if (waitpid(pid, &status, WNOHANG) > 0) {
+ /* the process exited */
+ tr_debug("tids_sweep_procs: TID process %d terminated.", pid);
+
+ g_array_remove_index_fast(tids->pids, ii-1); /* disturbs only indices >= ii-1 which we've already handled */
+ if (WIFEXITED(status) && (WEXITSTATUS(status) == 0)) {
+ tr_debug("tids_sweep_procs: TID process succeeded");
+ tids->req_count++;
+ } else {
+ tids->error_count++;
+
+ if (WIFEXITED(status)) {
+ tr_debug("tids_sweep_procs: TID process %d exited with status %d", pid, WTERMSIG(status));
+ } else if (WIFSIGNALED(status)) {
+ tr_debug("tids_sweep_procs: TID process %d terminated by signal %d", pid, WTERMSIG(status));
+ }
+ }
+ }
+ }
+}
+