On Thu, Mar 17, 2022 at 04:58:56PM +1030, Brett Lymn wrote: > Perhaps a shim program that manages a socket between it and the > underlying daemon - the shim can talk to inetd to coordinate the handoff > of an incoming connection and also being put back onto the idle pool > when the connection closes.
My point was: it is pretty simple and efficient to do in setups like httpd where the child and parent are the same and also can cooperate in special ways (like the preford children having a socketpair open to the parent and get their real stdin passed later on wakeup). But in general cases like inetd and child programs not specially written for this setup, it is impossible (or needs special tricks that will kill all the benefits like a shim program). The prefork idea is to have children ready for service as quickly as possible after a new connection has been established - avoiding delay by the OS for creating a new process and initialization time for execing the new servicing binary (and its internal initial initialization time). I don't see how that could be done in inetd context without adding special new kernel support. E.g. we could create a posix_spawn() flag that makes the child process stop immediately after loading and create a new syscall that (if called by the parent) replaces a set of filedescriptors for procs in this state and unblocks them. But maybe I am missing something or misunderstanding the optimization. Martin