[Mono-dev] System.Diagnostics.Process.Start() crashes when trying to allocate more than 255 processes

fcolle at libero.it fcolle at libero.it
Mon Jun 13 10:10:54 EDT 2011


Dear all,
 my linux application needs to start a big number (400) of processes. Each process is a mono application. 
I found the when trying to run more then 255 processes the runtime generates an exception.

The problem does NOT arise when executing other processes, like e.g. bash.

Example


The following two executables classes are a simple proof of concept. 
Just compile the second class and put in into the /tmp folder
MAIN PROGRAM


using System;
using System.Collections.Generic;
using System.Text;

using System.Diagnostics;

namespace CrashTester
{
    class Program
    {
        static void Main(string[] args)
        {
            ///In the real application this dictionary
            /// contains useful data. When a process dies,
            /// it can be started again with the same input parameters
            
            try
            {
                for (int i = 0; i < 260; i++)
                {
                    Console.Error.WriteLine("STARTING PROCESS: "+(i+1).ToString());
                    ProcessStartInfo startinfo = new ProcessStartInfo();
                    startinfo.FileName = "/usr/local/bin/mono";				
                    startinfo.Arguments = "/tmp/ToCrash.exe "+(i+1).ToString();
                    startinfo.UseShellExecute = false;
                    startinfo.RedirectStandardError = false;
                    startinfo.RedirectStandardOutput = false;
                    Process p = new Process();
                    p.StartInfo = startinfo;                    
                    p.Start();
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine("ERROR IN START PROCESS!");
            }
			
            Console.ReadKey();

        }
    }
}




CHILD PROCESSES


using System;
using System.Collections.Generic;
using System.Text;

namespace ToCrash
{
    class Program
    {
        static void Main(string[] args)
        {
			if((args!=null)&amp;&amp;(args.Length>0))
			{
              Console.WriteLine(args[0]);
			}
            Console.ReadLine();
        }
    }
} 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110613/8c3df448/attachment.html 


More information about the Mono-devel-list mailing list