Thread#kill doesn't kill processes inside a thread 
Author Message
 Thread#kill doesn't kill processes inside a thread

[This was first issued in ruby-de]

One thread uses system to run one (slow) program. The main thread kills
it but the forked program stays around after the script finishes.

Should Thread#kill not only mark the thread as dead but also kill its
children processes? Shouldn't there be some better way to kill children
than taking the pid and using Process.kill?

The only reference I could find was [ruby-talk:64895].

--
 _           _                            
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
        Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

MSDOS didn't get as bad as it is overnight -- it took over ten years
of careful development.



Mon, 31 Oct 2005 15:49:04 GMT  
 Thread#kill doesn't kill processes inside a thread
Hi,

In message "Thread#kill doesn't kill processes inside a thread"

|Should Thread#kill not only mark the thread as dead but also kill its
|children processes? Shouldn't there be some better way to kill children
|than taking the pid and using Process.kill?

No.  Threads are entities in the process, so it does not maintain
"child" processes.  Child processes are children of the parent
"processes" not threads.

If you want to kill child processes when the thread is down,

  th = Thread.new{
     Thread.current[:children] = []
     begin
       ... add child processes to Thread.current[:children]
     ensure
       Process.kill("TERM", *Thread.current[:children])
     end
  }

is the way to go.

                                                        matz.



Mon, 31 Oct 2005 16:46:11 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Killing processes without using 'kill'

2. Threads in Python version 1.5, thread doesn't start until calling process dies

3. How to kill a thread from another thread ?

4. threading: how to kill a (possibly blocked) thread?

5. threads killing other threads

6. Killing a thread from a 'controller'

7. vwait doesn't kill background processes on NT (only)

8. kill '-SIGHUP', pgid -vs- kill 'SIGHUP', 0

9. Vispro Rexx can't kill a rxftp thread

10. Threaded server doesn't run its threads

11. How can you kill a thread ???

12. Is there a REXX Kill Thread Function?

 

 
Powered by phpBB® Forum Software