Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ecsvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!mcnc!ecsvax!bet From: bet@ecsvax.UUCP (Bennett E. Todd III) Newsgroups: net.unix-wizards Subject: Timed self-destruct (for debugging programs that hang) Message-ID: <952@ecsvax.UUCP> Date: Wed, 18-Dec-85 22:58:43 EST Article-I.D.: ecsvax.952 Posted: Wed Dec 18 22:58:43 1985 Date-Received: Fri, 20-Dec-85 05:28:11 EST Reply-To: duccpc!bet@ecsvax.UUCP (Bennett E. Todd III) Distribution: net Organization: Duke University Computation Center Lines: 58 I was hacking on MicroEmacs this evening (trying to bring it up under 4.2) and kept hanging my terminal (MicroEmacs was reading RAW, but wasn't stripping parity; commands weren't recognized). So I started doing approximately the following: stty tostop # background jobs hang on tty output microem & # it gives PID, then the critter hangs stty -tostop # dasn't let this one hang! sleep 120;kill -9 pid & # where pid is filled in from above %microem # bring it to the foreground This worked well enough, but was a significant bother -- manually copying pids is a drag. So I tried to automate the process -- I wanted to be able to type timeout microem and have 120 seconds to play before it got killed off. I wrote the following. PLEASE note: I *know* it's ugly I *know* it shouldn't blat out all the inappropriate prompts I *realize* that it is unbearably inefficient It took me an hour or two to get it working at all (stubborn I am) and another couple of hours to give up on trying to clean it up. Any suggestions for how to straighten this sucker out and make it less grungy are welcome; in the interim, ugly as it is, it works. Hope you enjoy this: csh -i $* <<'EOF' set tmpfile=/tmp/timeout$$ stty tostop >/dev/tty $* /dev/tty & jobs -l >$tmpfile set pid=`grep $1 $tmpfile | awk '{print $3}'` rm $tmpfile stty -tostop >/dev/tty sleep 120 ; kill -9 $pid & %$1 EOF Like I said, about all that can be said for it is that it works, and I can't say that for any of my efforts to clean it up. If you can, please let me know how. One more quick thought -- note that the grep over the output of jobs -l could potentially match other jobs you have around, particularly if you are debugging a program with an unusually short name. -Bennett -- "Hypocrisy is the vaseline of social intercourse." (Who said that?) Bennett Todd -- Duke Computation Center, Durham, NC 27706-7756; (919) 684-3695 UUCP: ...{decvax,seismo,philabs,ihnp4,akgua}!mcnc!ecsvax!duccpc!bet