Yohanes Santoso
4/18/2005 11:36:00 AM
Guillaume Cottenceau <gcottenc@gmail.com> writes:
>> And then send a SIGTERM to that external process.
>
> This may be a dummy question, but how can I know the PID of the process?
rb(main):011:0> pipe = IO.popen("/bin/echo hi")
=> #<IO:0x401ac498>
irb(main):012:0> pipe.pid
=> 9113
irb(main):013:0> ps_pipe = IO.popen("ps aux|grep 9113")
=> #<IO:0x401a1a34>
irb(main):014:0> ps_pipe.gets
=> "ysantoso 9113 0.0 0.0 0 0 pts/6 Z+ 07:31 0:00
[echo] <defunct>\n"
irb(main):015:0> Process.waitall
=> [[9113, #<Process::Status: pid=9113,exited(0)>], [9114,
#<Process::Status: pid=9114,exited(0)>]]
pid 9113 is the echo process, and pid 9114 is the ps aux process.
Process.waitall/waitpid/waitpid2 is used to collect dead, uncollected
children (those with <defunct> in its process name, aka zombies).
You don't have to collect them if you don't want to. When the parent
process dies, the dead uncollected children will be collected by
process id 1 (init).
YS.