Blocks in threads should be killed if the command finishes first
Closed this issue · 1 comments
ripienaar commented
Given the following:
>> systemu("sleep 1") {|i| sleep 10;Process.kill 9, i} => [#<Process::Status: pid=4793,exited(0)>, "", ""] >> (irb):1:in `kill': No such process (Errno::ESRCH) from (irb):1:in `irb_binding'
I think if the command being run finishes before the thread for its block that thread should be killed else absolutely some weird stuff lke here can happen - and you have no guarantee that something else havnt since started on that pid
ahoward commented
you could say the same about this code
pid = fork{ sleep }
parent = !!pid
child = !parent
if parent
sleep(rand * 100)
Process.kill(-9, pid) # you actually have no idea here, if the pid has been recycled!
end
you need to do way more work to know, in the general case, if a pid is your child such as maintaining unix domain sockets to communicate between the parent/child (a lifeline) or using the Process based call to tell.
knowing that a particular pid is
- yours
- alive
- not recycled
is a general problem that's way outside the scope of a library