Xref: utzoo alt.sources:1094 comp.unix.wizards:18440
Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!hp4nl!star.cs.vu.nl!maart
From: maart@cs.vu.nl (Maarten Litmaath)
Newsgroups: alt.sources,comp.unix.wizards
Subject: timeout command in shell script!
Summary: why use a C program if a small script will do?
Message-ID: <3464@star.cs.vu.nl>
Date: 3 Oct 89 06:00:41 GMT
References: <1925@convex.UUCP> <3312@amelia.nas.nasa.gov>
Organization: V.U. Informatica, Amsterdam, the Netherlands
Lines: 53
: This is a shar archive. Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
: --------------------------- cut here --------------------------
PATH=/bin:/usr/bin:/usr/ucb
echo Extracting 'timeout'
sed 's/^X//' > 'timeout' << '+ END-OF-FILE ''timeout'
X#!/bin/sh
X# @(#)timeout 1.0 89/10/03 Maarten Litmaath
X
Xprog=`basename $0`
Xusage="Usage: $prog "
X
Xcase $1 in
X[0-9]*)
X timeout=$1
X shift
X ;;
X*)
X echo "$usage" >&2
X exit 2
Xesac
X
Xcase $# in
X0)
X echo "$usage" >&2
X exit 2
Xesac
X
Xexec 3>&2 2> /dev/null
X
Xtrap 'echo TIMEOUT >&3; exit 1' 1
Xtrap '' 14
X
Xsh -c '(sleep '$timeout'; kill -1 '$$'; kill -9 $$) & exec "$@" 2>&3' \
X "$prog" "$@"
X
Xtrap '' 1
Xkill -14 -$$
X
Xexit 0
+ END-OF-FILE timeout
chmod 'u=rwx,g=rx,o=rx' 'timeout'
set `wc -c 'timeout'`
count=$1
case $count in
440) :;;
*) echo 'Bad character count in ''timeout' >&2
echo 'Count should be 440' >&2
esac
exit 0
--
Did Andy Tanenbaum get his programming |Maarten Litmaath @ VU Amsterdam:
instruction from a Cereal box? (Sam McCrea)|maart@cs.vu.nl, mcvax!botter!maart