liburing
liburing copied to clipboard
Non-blocking `waitpid`?
Does this exist? Should we create it? Or should we prefer pidfd?
What's the deal with liburing?
Don't we have WNOHANG for this?
Quoted from man 2 waitpid:
pid_t waitpid(pid_t pid, int *wstatus, int options);
[...]
The value of options is an OR of zero or more of the following constants:
[...]
WNOHANG
return immediately if no child has exited.
[...]
RETURN VALUE
waitpid(): on success, returns the process ID of the child whose state has changed; if WNOHANG was specified and one or more child(ren) specified by pid exist, but have not yet
changed state, then 0 is returned. On error, -1 is returned.
@ammarfaizi2 I'm not sure how WNOHANG relates to my use case? Are you suggesting I should call this for every PID in a tight loop?
@ioquatix oh right, I missed the use case. Now I think it makes sense to poll for waitpid.
On more recent Linux we can use pidfd_open. But I'm not sure if there is better approach. Maybe we can introduce OP_WAITPID.
For reference, here is what I did: https://github.com/socketry/event/blob/1278eab1d7b1af9d5aa3d5f4acd246e686786315/ext/event/backend/uring.c#L154-L174
Does this exist? Should we create it? Or should we prefer pidfd?
@ioquatix, Is it somewhat CPU time limited in task waiting? If it's just an occasional thing and there are no other problems, than I'd say pidfd is a better option
In some cases there could be hundreds of child processes. It may be nice to provide a better interface, for consistency sake.