smol-rs / async-process

Async interface for working with processes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use a more efficient strategy for waiting on processes

notgull opened this issue · comments

Right now, we use SIGPROC to wait for process events on Unix and thread pooling to wait for process events on Windows. This is a very inefficient strategy that doesn't scale for many child processes, like using poll() for I/O notification.

Most operating systems have better ways of handling events like this.

  • Linux has pidfd, which can be registered directly into async-io.
  • BSD has EVFILT_PROC, which is now exposed in async-io.
  • Windows has waitable handles, which need to be exposed in async-io. They can also be made more efficient on the polling side, see smol-rs/async-io#25

Will look into this

How this would probably be done:

  • Split the signal-handling logic out of Reaper and move it to a signal.rs file.
  • Create an alternative pidfd.rs file that implements the Reaper logic using Async<OwnedFd> and pidfd_open.
  • Child::wait should be implemented by calling readable() on the PIDFD to wait.
  • Zombie processes should be pushed into an executor that replaces the reap() function.

Sorry for the delay!
Will start working on this tomorrow

@mamaicode Great! Let me know if you need any guidance; I can hop in a Matrix/Discord call for pair programming if needed.

pidfd has been implemented for Linux. However, we should also be able to implement this for Windows and BSD as well.