after I removed i=$((i+1)), it doesn't work like your side
I want get
after 5s (timeout=5), the script will be stopped and with it's subprocess stopped too, and alos get where it stopped, here is "echo "at $i interupt" to tell where it stopped
things get better, but I find if I change the "sleep 1" to "sleep 100", after 5s, it doesn't kill the "sleep 100", and looks it doesn't kill the mainpid too, so the cleanup doesn't execute.
BTW, can you explain the usage you offered, thanks
Bash and dash not work but ksh93 can do it.
Problem is pipe = how to do it.
Difference is how to think about pipe: like you think it = "programmer way" = ksh (88+93) or works it like it has defined, own process = bash, posix, dash, ... = you kill the pipe 1st process.
command line is process to kill (=ksh) or current process kill (bourne shell, bash, dash,...).
The best example is pipe and read. I don't say which works correctly, because both works as they has planned. But I like more David Korn way to think about it. It use shared mem between piped subprocess = sub process create variable and I can use it in the parent process.
# ksh only
echo a b c | read var1 var2
echo $var1 : $var2
All other shells you need to use io redirection, then it's same process, works also in ksh:
read var1 var2 <<EOF
$(echo a b c)
EOF
echo $var1 : $var2