liburing icon indicating copy to clipboard operation
liburing copied to clipboard

Non-blocking `waitpid`?

Open ioquatix opened this issue 4 years ago • 7 comments
trafficstars

Does this exist? Should we create it? Or should we prefer pidfd?

ioquatix avatar Jun 12 '21 00:06 ioquatix

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 avatar Jun 12 '21 02:06 ammarfaizi2

@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 avatar Jun 12 '21 02:06 ioquatix

@ioquatix oh right, I missed the use case. Now I think it makes sense to poll for waitpid.

ammarfaizi2 avatar Jun 12 '21 02:06 ammarfaizi2

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.

ioquatix avatar Jun 12 '21 08:06 ioquatix

For reference, here is what I did: https://github.com/socketry/event/blob/1278eab1d7b1af9d5aa3d5f4acd246e686786315/ext/event/backend/uring.c#L154-L174

ioquatix avatar Jun 12 '21 08:06 ioquatix

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

isilence avatar Jun 14 '21 11:06 isilence

In some cases there could be hundreds of child processes. It may be nice to provide a better interface, for consistency sake.

ioquatix avatar Jun 14 '21 12:06 ioquatix