Killing the correct process
Maarten Litmaath
maart at cs.vu.nl
Wed Feb 7 01:26:18 AEST 1990
In article <22332 at adm.BRL.MIL>,
marwood at ncs.dnd.ca (Gordon Marwood) wants to timeout ftp.
How about using the following general purpose script? If that's out of the
question, the script might still give you a hint how to solve your problem.
----------8<----------8<----------8<----------8<----------8<----------
#!/bin/sh
# @(#)timeout 4.1 90/01/10 Maarten Litmaath
prog=`basename $0`
verbose=0
case $1 in
-v)
verbose=1
shift
esac
expr $# \< 2 \| 0"$1" : '.*[^0-9]' > /dev/null && {
echo "Usage: $prog [-v] <timeout in seconds> <command>" >&2
exit 2
}
timeout=$1
shift
exec 3>&1 4>&2 2> /dev/null
pid=`
sh -c '
(sleep '$timeout' > /dev/null & echo $!; exec >&-;
wait; kill -9 $$) & exec "$@" >&3 3>&- 2>&4 4>&-
' $prog "$@"
`
kill -9 $pid && exit 0
test $verbose = 1 && echo TIMEOUT >&4
exit 1
--
The meek get the earth, Henry the moon, the rest of us have other plans. |
Maarten Litmaath @ VU Amsterdam: maart at cs.vu.nl, uunet!mcsun!botter!maart
More information about the Comp.unix.questions
mailing list