[Mono-dev] System.Unix.Native.Syscall.fork is commented out

Avery Pennarun apenwarr at gmail.com
Wed Nov 5 18:22:56 EST 2008


On Wed, Nov 5, 2008 at 6:20 PM, Jonathan Pryor <jonpryor at vt.edu> wrote:
> On Wed, 2008-11-05 at 22:13 +0000, James Mansion wrote:
>> Jonathan Pryor wrote:
>> > That still wouldn't work, as *before* Main() is invoked there are
>> > already multiple threads running.  You might not have the unknown lock
>> > state issue, but you will have the runtime assuming that threads exist
>> > which won't exist in the child process.  Oops.
>> >
>> Isn't this an opportunity for 'embedding mono' with an explicit
>> dynamic load of the mono runtime, so the main that runs is a C program
>> that detaches first and sorts itself out and then loads up and
>> initialises the mono runtime?
>
> Yes, though this would be outside of Mono.Posix's scope and thus would
> require that you write & maintain a C "bootstrap" program...
>
> Not difficult, but not entirely in C# either.

Also, people often forget that daemons are supposed to do their setup
and *then* fork into the background, not fork into the background
right away.  For example, when you start syslogd, you have a right to
expect that /dev/log will be listening by the time it forks into the
background.  Otherwise you could lose syslog messages produced after
it forks but before it starts listening on its socket.

Since presumably any sockets would be set up from the C# side of the
program, using a C wrapper would be a little complicated.

Avery


More information about the Mono-devel-list mailing list