I've been trying to duplicate some functionality of a perl script I
have...

I need to be able to launch an external program (either via system, or
open("|somecommand") and then kill the external program if it hasn't died
in a specified time.

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 ran it a few times and did a 'ps -aux | grep du' in another xterm and
found that the process id for the actual du command was 863, so killing
f.pid (862) had no effect.

So the question is: when you do an 'open("|somesystemcommand")' there seem
to be two forks occuring - is this true?  One fork for the shell and
another fork for the command to be run in that shell - is this correct?
If that is the case, then how do I get the pid for the system command that
I'm running with the open so that it can be killed after some amount of
time?

All this seems to also apply to 'system("somesystemcommand")' as well.

Or from another angle: Since I have the pid for the implicit shell (f.pid)
is there a way to kill that shell AND it's child (the du command in this
case)?

Phil