reaper: new module, uses a signalfd to wait() on child processes

Use a signalfd to listen for SIGCHLD signals.

When we receive a SIGCHLD over the signalfd, reap all dead children by
looping over all registered child PIDs and call waitpid(WNOHANG) on
them.
This commit is contained in:
Daniel Eklöf 2020-05-21 20:15:10 +02:00
parent 5600cc68c0
commit f49742ebba
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 161 additions and 0 deletions

12
reaper.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <sys/wait.h>
#include "fdm.h"
struct reaper;
struct reaper *reaper_init(struct fdm *fdm);
void reaper_destroy(struct reaper *reaper);
void reaper_add(struct reaper *reaper, pid_t pid);