Subprocess lives on..........
James Logan III
logan at vsedev.VSE.COM
Wed Nov 16 02:33:43 AEST 1988
In article <167 at heart-of-gold> jc at heart-of-gold (John M Chambers) writes:
>Can anyone figure out how to make the while-loop exit when graf terminates
>and the script exits? I've tried playing arount with $? and traps, but I
>clearly don't know what I'm doing. I even tried a "kill -HUP 0", and it
>worked. But all my windows also exited and I got a login prompt. Sorta
>overkill, if you ask me.
The shell really should exit without leaving the while loop
running (at least under Sys V) because the while loop will be
writing on a pipe with no one to read it. This SHOULD cause a
SIGPIPE signal to kill the subshell that's running the while
loop. Even if the subshell was ignoring the SIGPIPE signal, I
can't see how it would start writing to your terminal! My first
guess at a fix is this:
#!/bin/sh
# GrafRoute host
# This generates a graph of the "netstat -r" Use data for host,
# which may be the destination or the gateway.
#
(
trap "exit 0" 1 13 15;
while true; do
netstat -r |
grep $1 |
cut -c49-59;
sleep 6;
done;
) |
graf -PD +H +V -a -T'Route "'$1'" packet rate';
I don't know what SunView does to terminate the process. Maybe
it sends a SIGHUP or a SIGTERM? Anyway, this script will exit
when it receives either signal. (Theoretically!)
-Jim
--
Jim Logan logan at vsedev.vse.com
(703) 892-0002 uucp: ..!uunet!vsedev!logan
inet: logan%vsedev.vse.com at uunet.uu.net
More information about the Comp.unix.questions
mailing list