Hi all,
I find an interesting behavior of Thread#kill, I am not sure if this is a
bug.
Please tell me If my test code has any problems.
Require sys-proctable and parallel to test.
require 'open3'
require 'parallel'
require 'sys/proctable'
class MemoryOut < StandardError
end
jobs = *(1..10000)
Parallel.map(jobs, :in_threads=>20) do
mem_thr = Thread.new do
100.times do|i|
begin
Sys::ProcTable.ps
rescue Errno::ENOENT, Errno::ESRCH
# ProcTable bug
end
if i > 5
raise MemoryOut
end
sleep 0.1
end
end
open_thr = Thread.new do
Open3.popen2e "sleep 2" do |i, o, w|
w.value
end
#mem_thr.kill
end
begin
mem_thr.join
rescue MemoryOut
end
open_thr.join
end
This program seems OK and I can not find out the problem.
If I add back the commented out line "mem_thr.kill", then fds opened by
ProcTable can not be closed, finally causes the error "too many opened
files".
Use the command "lsof" to check this, can see many files under /proc are
not closed.
If I comment out the kill again, everything goes well.
Thanks,
Jianjun.