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

Avery Pennarun apenwarr at gmail.com
Tue Sep 2 23:42:00 EDT 2008


Hi all,

I'm attempting to write a simple daemon in mono that should background
itself after starting correctly.  Essentially, it should fork() and
then the parent should exit(0) while the child process continues.

I've gotten this working with the (apparently now obsolete)
Mono.Posix.Syscall class.  However, in the newer
Mono.Unix.Native.Syscall, we find this:

#if false
                // fork(2)
                //    pid_t fork(void);
                [DllImport (LIBC, SetLastError=true)]
                [Obsolete ("DO NOT directly call fork(2); it bypasses essential
                                "shutdown code.\nUse System.Diagnostics.Process
                private static extern int fork ();

                // vfork(2)
                //    pid_t vfork(void);
                [DllImport (LIBC, SetLastError=true)]
                [Obsolete ("DO NOT directly call vfork(2); it bypasses essential
                                "shutdown code.\nUse System.Diagnostics.Process
                private static extern int vfork ();
#endif

Apparently, fork() was originally marked obsolete, then commented out
completely.

However, I don't understand the rationale here.  It seems to me that
fork() has nothing to do with shutdown, and thus cannot possibly
bypass "essential shutdown code."  On the other hand, Syscall.execve
is *not* obsolete and *does* bypass shutdown code.  Furthermore, the
recommended System.Diagnostics.Process class provides no equivalent to
fork(), so I'm not sure why it's being recommended.

What's the rationale here?

Thanks,

Avery


More information about the Mono-devel-list mailing list