[Mono-dev] fork() in Mono

Miguel de Icaza miguel at microsoft.com
Wed Jan 3 20:05:45 UTC 2018

One last bit:

Nowadays it should be possible to fork() and perform an exec or die quickly, provided you do not need the additional servies like the GC thread.

´╗┐On 12/4/17, 7:06 AM, "Mono-devel-list on behalf of Robert Jordan" <mono-devel-list-bounces at lists.dot.net on behalf of robertj at gmx.net> wrote:

    On 04.12.2017 02:23, Gene Thomas wrote:
    > What happens specifically?|fork()|starts a process, it does not shut 
    > anything down?|fork()|should just work, does it not (effectively (copy 
    > on write)) copy the entire VM which then each shuts down 
    > independently?|fork()|does work in Python on Unix (multiprocessing module).
    > |fork()|is powerful, it supports using processes as an alternative to 
    > threads. One can not test for a one in a million race 
    > condition.|System.Diagnostics.Process|only replaces|fork()|then|exec()|. 
    > I wish to use|fork()|to support replicated processes, starting with a 
    > complete copy of the application's state greatly simplifies this.
    You may want to look at fork(2)'s specs, especially to those parts
    regarding multithreading.
    The forked child will start with one running thread only, etc.
    This means that W/out some kind of advanced runtime support
    for fork(2), you won't go very far. The GC and other service
    threads won't run anymore, etc.
    For toying around, you can test fork(2) even w/out Mono.Posix:
    using System;
    using System.Runtime.InteropServices;
    class Program {
    	public static extern int fork();
    	public static void Main()
    		int pid = fork();
    		if (pid == -1) {
    			Console.WriteLine("fork failed");
    		} else if (pid == 0) {
    			Console.WriteLine ("child");
    		} else
    			Console.WriteLine ("parent, child's pid={0}", pid);
    Mono-devel-list mailing list
    Mono-devel-list at lists.dot.net

More information about the Mono-devel-list mailing list