From: Akio Tajima Date: 2011-03-22T23:57:29+09:00 Subject: [ruby-dev:43344] [Ruby 1.9 - Bug #4518][Open] (win32) waitpid returns exit code while the child process still alive. Issue #4518 has been reported by Akio Tajima. ---------------------------------------- Bug #4518: (win32) waitpid returns exit code while the child process still alive. http://redmine.ruby-lang.org/issues/4518 Author: Akio Tajima Status: Open Priority: Normal Assignee: Akio Tajima Category: core Target version: 1.9.3 ruby -v: ruby 1.9.3dev (2011-03-22) [i386-mswin32_100] 以下のスクリプトを実行すると2~4回目の繰り返しでエラーとなります(test/test_process.rbから抽出して加工)。 # coding: utf-8 require 'tmpdir' require 'pathname' def with_tmpchdir Dir.mktmpdir {|d| p d d = Pathname.new(d).realpath.to_s Dir.chdir(d) { yield d } } end def write_file(filename, content) File.open(filename, "w") {|f| f << content } end 10.times do with_tmpchdir do write_file("foo", "sleep 0.1") ps = (0...3).map { spawn("ruby", "foo") }.sort ss = Process.waitall end end エラー: C:/Users/arton/Documents/ruby/src/rubytrunk/lib/fileutils.rb:1308:in `rmdir': Permission denied - :/Users/arton/AppData/Local/Temp/d20110322-7200-dxjpnx (Errno::EACCES) from C:/Users/arton/Documents/ruby/src/rubytrunk/lib/fileutils.rb:1308:in `block in remove_dir1' ... WIN32APIのGetExitCodeProcessがアプリケーションの終了ステータスを返した時点では、まだプロセスが終了していないことがあるため、子プロセスがテンポラリディレクトリを利用していてEACCESとなるようです。 (実行環境が、4コア Xeonというのが利いているとは思います) -- http://redmine.ruby-lang.org