aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstddjb/waitpids_nohang.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/waitpids_nohang.c')
-rw-r--r--src/libstddjb/waitpids_nohang.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstddjb/waitpids_nohang.c b/src/libstddjb/waitpids_nohang.c
new file mode 100644
index 0000000..23f03de
--- /dev/null
+++ b/src/libstddjb/waitpids_nohang.c
@@ -0,0 +1,19 @@
+/* ISC license. */
+
+#include <sys/wait.h>
+#include <skalibs/djbunix.h>
+
+ /*
+ waitpids_nohang (defined here): only reap pids, don't touch the rest
+ */
+
+int waitpids_nohang (pid_t const *pids, unsigned int len, int *wstat)
+{
+ for (unsigned int i = 0 ; i < len ; i++)
+ {
+ pid_t r = waitpid_nohang(pids[i], wstat) ;
+ if (r == -1) return -1-i ;
+ else if (r == pids[i]) return 1+i ;
+ }
+ return 0 ;
+}