aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstddjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/wait_pid_nohang.c5
-rw-r--r--src/libstddjb/wait_pids_nohang.c4
-rw-r--r--src/libstddjb/waitpids_nohang.c19
3 files changed, 28 insertions, 0 deletions
diff --git a/src/libstddjb/wait_pid_nohang.c b/src/libstddjb/wait_pid_nohang.c
index 7b27bbe..f22a222 100644
--- a/src/libstddjb/wait_pid_nohang.c
+++ b/src/libstddjb/wait_pid_nohang.c
@@ -3,6 +3,11 @@
#include <sys/wait.h>
#include <skalibs/djbunix.h>
+ /*
+ wait_pid_nohang (defined here): reaps everything until it gets pid
+ waitpid_nohang (macro): only tries to reap pid, doesn't touch others
+ */
+
pid_t wait_pid_nohang (pid_t pid, int *wstat)
{
int w = 0 ;
diff --git a/src/libstddjb/wait_pids_nohang.c b/src/libstddjb/wait_pids_nohang.c
index c13ddec..f56c065 100644
--- a/src/libstddjb/wait_pids_nohang.c
+++ b/src/libstddjb/wait_pids_nohang.c
@@ -3,6 +3,10 @@
#include <sys/wait.h>
#include <skalibs/djbunix.h>
+ /*
+ wait_pids_nohang (with the underscore): reap everything, report if in pids
+ */
+
int wait_pids_nohang (pid_t const *pids, unsigned int len, int *wstat)
{
for (;;)
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 ;
+}