In message "[ruby-talk:8584] system, open("|..") and process ids"
on 01/01/04, Phil Tomson <ptkwt / user2.teleport.com> writes:
>Currently I'm trying something like:
>
>include Process
>puts "Parent pid is: #{Process.pid}"
>open("|du / > tmp") do |f| #run some command that takes a while
> puts "kidpid is #{f.pid}"
> sleep 3 #or however long you want to wait
> kill "SIGTERM", f.pid
>end
>puts "do more stuff afterwards"
>
>I get something like (running on Linux):
>Parent pid is: 861
>kidpid is: 862
>
>and then about a second later:
>do more stuff afterwards
>
>All fine and good...
>HOWEVER, the "du /" is still running after the last message is printed.
>It was NOT killed.
I'm sorry for non-direct answer, but how about this?
pid = `du / > tmp & echo $!`.to_i
sleep 3
Process.kill("SIGKILL", pid)
It's a practice of principle: `Ask shell about the shell' :-)
Hope this helps,
-- Gotoken