golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.72k stars 17.62k forks source link

os: use pidfd_open with epoll on Linux instead of blocking wait in blockUntilWaitable #60320

Open mitar opened 1 year ago

mitar commented 1 year ago

My understanding is that in blockUntilWaitable the waitid call blocks the thread you call it on. On Linux, we could instead use pidfd_open and then monitor the file descriptor with epool:

When the process that it refers to terminates, these interfaces (e.g., epool) indicate the file descriptor as readable.

I think this would then not block the thread?

ianlancetaylor commented 1 year ago

I don't see any API change here, so this doesn't have to be a proposal. Taking it out of the proposal process.

mitar commented 1 year ago

OK, I made a draft of the implementation in #60461 to test how would this work out. It is not yet perfect (see comments on Gerrit), but it gives me/us something to play around. I think it works pretty nice.

gopherbot commented 1 year ago

Change https://go.dev/cl/498615 mentions this issue: os/exec: use pidfd for waiting and signaling of processes