Glib child processes
Marc Lehmann
schmorp at schmorp.de
Thu Aug 11 23:51:28 CEST 2011
On Wed, Aug 10, 2011 at 11:20:11AM +1000, Kevin Ryde <user42 at zip.com.au> wrote:
> Marc Lehmann <schmorp at schmorp.de> writes:
> >
> > for modules and libraries
>
> I suppose a module usually has no business reaping globally.
Well, a module has no business reaping, really, thats what AnyEvent itself
should do *g*. Seriously though, the uses are not extremely common, but it is
the only way to catch child exits for children you didn't know about:
AnyEvent tries hard to get corner cases and all possible functionalities
right, but of course can only offer as much as event loops do.
Compatibility with other modules or libraries that use the same underlying
event loop suually wins though.
> Incidentally, in the pod of "CHILD PROCESS WATCHERS", for the bit where
> it says system() works, is that because a good system() implementation
> temporarily blocks SIGCHLD?
No, because all event loops, I hope, do the right thing and either reap
only registered children (which glib does, unfortunately it means you
can't have two watchers for the same pid) or do not reap in the signal
handler (which would fortunately be hard to do anyway, so no modern event
loop should do that).
So it's like:
system () entered...
fork + exec
SIGCHLD handler sets flag etc. # either now, or after the waitpid
waitpid
system returns
event loop is entered
SIGCHLD flag is set, reap children
IT breaks down when a program uses multiple threads, but thats not
strictly an event loop thing, as almost everything unixy breaks down (for
example, you can't use fork anymore on POSIX).
> I suppose could put in something to advertise whether it works or not,
> if it's going to go only sometimes.
backends are required to croak if they don't support it, which afaics all
of them do (well, none of them do or did until AnyEvent 6 is released with
the new glib backend).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the anyevent
mailing list