diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-08-31 23:45:35 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-08-31 23:45:35 +0000 |
| commit | 233e3ccb96525e7a6af31a60b891badd8d73c5a4 (patch) | |
| tree | e3232d7a7364537e76121e516abf6ef307191db2 /src/libstddjb | |
| parent | 4f42e46eff746603a0762c0299cc63d9c7004bcf (diff) | |
| download | skalibs-233e3ccb96525e7a6af31a60b891badd8d73c5a4.tar.gz | |
Add pthread_create_flat, waitpid_nohang, waitpids_nohang
Diffstat (limited to 'src/libstddjb')
| -rw-r--r-- | src/libstddjb/wait_pid_nohang.c | 5 | ||||
| -rw-r--r-- | src/libstddjb/wait_pids_nohang.c | 4 | ||||
| -rw-r--r-- | src/libstddjb/waitpids_nohang.c | 19 |
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 ; +} |
