This program doesn't work when run as root either.
I believe you're thinking of SIGKILL. SIGTERM is a perfectly normal signal. If I change the kill command to just send a normal signal to $kidpid, then the child process prints the TERM message, but not the grandchildren. Similarly, if you make the sleeps a little longer, you can send TERM signals by hand to individual grandchildren, and they print the message.
Snippets of code should be wrapped in
<code> tags not<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).