Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utcsri!uthub!ecf!larry From: larry@ecf.UUCP Newsgroups: comp.bugs.4bsd Subject: Re: Programs can thwart cpu time limit Message-ID: <164@ecf.toronto.edu> Date: Tue, 26-May-87 09:09:17 EDT Article-I.D.: ecf.164 Posted: Tue May 26 09:09:17 1987 Date-Received: Wed, 27-May-87 01:14:49 EDT References: <6208@shemp.UCLA.EDU> Reply-To: larry@ecf.toronto.edu (Larry Philps) Distribution: world Organization: Engineering Computing Facility, University of Toronto Lines: 57 Keywords: cputime RLIMIT_CPU SIGXCPU Summary: Add a sigkill In article <6208@shemp.UCLA.EDU> heather@CS.UCLA.EDU (Heather Burris) writes: > >I believe that the following behavior is a bug: > > I write a program that specifies a hard and a soft cpu time > limit using the setrlimit() system call. I also use > signal() to catch SIGXCPU signals (cpu time exceeded). > ... > Instead what happens is that the the signal handler gets > called once every 5 seconds from the time I hit the soft > limit to the time I hit the hard limit (see line 144 of > kern_clock.c for 5 second figure-- why isn't this documented). > At that point, the signal handler is constantly called. Yup, I think that is a bug also. We do enforce resource limits on our student who are the world's most adept at writing programs with infinite loops. The following trivial fix will cause the program to die when it exceeds the hard limit. *** /tmp/,RCSt1024359 Tue May 26 09:02:48 1987 --- kern_clock.c Wed Nov 5 11:35:10 1986 *************** *** 4,10 **** * specifies the terms and conditions for redistribution. * * @(#)kern_clock.c 7.1 (Berkeley) 6/5/86 ! * $Header: kern_clock.c,v 1.2 86/10/21 14:55:15 larry Exp $ */ #include "../machine/reg.h" --- 4,10 ---- * specifies the terms and conditions for redistribution. * * @(#)kern_clock.c 7.1 (Berkeley) 6/5/86 ! * $Header: kern_clock.c,v 1.3 86/11/05 11:35:05 larry Exp $ */ #include "../machine/reg.h" *************** *** 146,151 **** --- 146,154 ---- if (u.u_rlimit[RLIMIT_CPU].rlim_cur < u.u_rlimit[RLIMIT_CPU].rlim_max) u.u_rlimit[RLIMIT_CPU].rlim_cur += 5; + else + /* kill the proc if hard cpu limit exceeded */ + psignal(u.u_procp, SIGKILL); } if (timerisset(&u.u_timer[ITIMER_PROF].it_value) && itimerdecr(&u.u_timer[ITIMER_PROF], tick) == 0) Larry Philps Engineering Computing Facility University of Toronto NEW PATH: larry@ecf.toronto.edu USENET: {linus, ihnp4, allegra, decvax, floyd}!utcsri!ecf!larry CSNET: larry@Toronto ARPA: larry%Toronto@CSNet-Relay BITNET: larry@ecf.utoronto.BITNET