From: "Martin aus Chemnitz" <MartinAusChemnitz / gmx.net> > > Under Windows, I want to start an external program and kill it on > exitting my Ruby script. > > begin > $t = Thread.new { system("everlasting") } > ... > ensure > $t.kill > end > > does not stop the everlasting program, it stops $t, not its child > processes. Such a command is urgently needed! > > Yukihiro Matsumoto writes in > <1052988371.738185.28868.nullmailer / picachu.netlab.jp>: > > 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 > > } > but I think I can't get the PID of a system call either. > > I would be glad if such a feature could be implemented. (Or, of course, > if anyone can tell me suitable solution.) I'm guessing the problem is your "everlasting" program spawns itself in the manner of rubyw.exe, where it does sort of the windows equivalent of daemonizing itself. So your system("everlasting") call returns immediately, and your "everlasting.exe" is launching as a separate process, for which you have no way (that I know of) of obtaining the PID. Maybe a windows guru can help. I'm doubtful this is a behavior ruby has any control over. If I understand correctly, you may be up against a fundamental problem with Windows' way of launching non-console applications. (I guess there must be some way to solve it, if one were to write an extension, since certainly the Visual Studio debugger is able to launch non-console applications but obtain their PID's.) Sorry I can't be of more help, Regards, Bill