1
votes

I have to run external executables from my Ruby code on Windows, for that, i'm using the

    spawn  

method.
Sometimes i have to run the same program very often, it executes itself very quickly then exits right away. It's not critical that i simply don't run the program for some seconds.

The problem is - sometimes i get this error :

C:/Program Files/Ruby22/lib/ruby/2.2.0/open3.rb:193:in `spawn': 
Resource temporarily unavailable - identify (Errno::EAGAIN)````

My attempts to safely rescue and/or prevent the main Ruby program from crashing failed with any method i tried, even with this example :

begin
  spawn( "#{cmd}" )
rescue Exception
  sleep 0.3
end

i couldn't get right results.

How to rescue this case OR How to correctly thread/fork and prevent the main program from crashing?
(if possible - without tweaking the kernel / other params to increase maximum processes?).

1

1 Answers

2
votes

I found out by carefully rereading the Ruby Wiki

The parent process should use Process.wait to collect the termination
 status of its child or use Process.detach to register disinterest in their 
status; otherwise, the operating system may accumulate zombie processes.

I don't have this error anymore if i do :

pid = spawn( "#{cmd}" )
Process.detach pid