Re: GChildWatch source -- take two



Thus spake Jonathan Blandford:
> No, I meant to have g_child_watch_add(-1) have the same effect as
> calling waitpid(-1).  That is to say, it'll give notice of every child
> process that exits.  g_child_watch_add(0) will give notice of children
> in the process group, just as waitpid(0) does.  With this behavior, it
> makes more sense to check the return value of the call.

This feature might be useful, but there are some points that would be
difficult to implement (or would require quite a few modifications in
the patch):

Do you call waitpid(-1)?
- If you do, you'd have some bad interactions with the other waitpids
  (there's no guarantee that waitpid(-1) won't reap a child that should
  have been reaped by a more specific waitpid).  Even if you guarantee
  that you'll call waitpid(-1) only after the other waitpids, you'll
  still have races;
- If you don't, it'll be hard (impossible?) to handle
  g_child_watch_add(0).  And g_child_watch_add(-1) will only be able to
  give notice of the children registered with g_child_watch_add
- You could _only_ call waitpid(-1) (say, in the signal handler, and
  then you write pid and status in the pipe), but that would require
  major modifications.

I'd say to leave this out for now and see if somebody complains - you
may have to check that pid > 0 in g_child_watch_source_new, to guarantee
that nobody tries to use this behind GLib.

Also, with the current implementation, if you register two sources for
the same pid, only one will be called - the docs should probably mention
that.

Alexis



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]