I seemed to have received this off-list. Bringing it back in case
anyone else has something to offer.
On Nov 8, 2012, at 23:18, Benoit Chesneau wrote:
I want to supervise a bunch of OS processes calling different on a
machine and collect their exit so I can eventually restart one or
collect the result of this process.
I can probably do it using sync.WaitGroups or a channel indeed but was
wondering how efficient it can be.
The only reason you'd worry about efficiency in supervising processes
is if you're polling, I'd think. Most of the time, the processes are
running and your app is idle.
I don't know why you'd not do the most obvious thing -- just spawn a
goroutine for every process you want to supervise and have it manage
that child. You can have a shared channel to send the results from all
of them, or do so in isolation or whatever.
One goroutine per process is pretty much required to achieve your goal
and it's likely the easiest way to do it and at least as efficient as
whatever you'd be doing to track the state of each process so you'd know
what died or emitted output anyway.