title: Ruby, strange forked processes behaviour on MacOS vs Debian
body: <p>Using Ruby (tested with versions 2.6.9, 2.7.5, 3.0.3, 3.1.1) and forking processes to handle socket communication there seems to be a huge difference between MacOS OSX and a Debian Linux.</p>
  <p>While running on Debian, the forked processes get called in a balanced manner - that mean: if having 10 tcp server forks and running 100 client calls, each fork will get 10 calls. The order of the pid call stack is also always the same even not ordered by pid (caused by load when instantiating the forks).</p>
  <p>Doing the same on a MacOS OSX (Catalina) the forked processes will not get called balanced - that mean: &quot;pid A&quot; might get called 23 or whatever times while e.g. &quot;pid G&quot; was never used.</p>
  <p>Sample code (originally from: <a href="https://relaxdiego.com/2017/02/load-balancing-sockets.html" rel="nofollow noreferrer">https://relaxdiego.com/2017/02/load-balancing-sockets.html</a>)</p>
  <pre class="lang-rb prettyprint-override"><code>#!/usr/bin/env ruby
  
  # server.rb
  
  require 'socket'
  
  # Open a socket
  socket = TCPServer.open('0.0.0.0', 9999)
  puts &quot;Server started ...&quot;
  
  # For keeping track of children pids
  wpids = []
  
  # Forward any relevant signals to the child processes.
  [:INT, :QUIT].each do |signal|
    Signal.trap(signal) {
      wpids.each { |wpid| Process.kill(:KILL, wpid) }
    }
  end
  
  5.times {
    wpids &lt;&lt; fork do
      loop {
        connection = socket.accept
        connection.puts &quot;Hello from #{ Process.pid }&quot;
        connection.close
      }
    end
  }
  
  Process.waitall
  </code></pre>
  <p>Run some netcat to the server on a second terminal:</p>
  <pre class="lang-bash prettyprint-override"><code>for i in {1..20}; do nc -d localhost 9999; done
  </code></pre>
  <p>As said: if running on Linux each forked process will get 4 calls - doing same on MacOS OSX its a random usage per forked process.</p>
  <p>Any solution or correction to make it work on MacOS OSX in a balanced manner also?</p>