Program to renice jobs

Ron Nash nash at ucselx.sdsu.edu
Sat Oct 20 03:32:29 AEST 1990


In article <1990Oct19.094659 at granada.mit.edu> andrew at granada.mit.edu (Andrew Gunstensen) writes:
>Is there a good method of renicing jobs automatically once they
>have exceeded some CPU time limit?  My problem is that we
>have a large number of (relatively UNIX-clueless) users who
>tend to run largish background jobs on our Sun network 
>at niceness 0. 
>This noticeably degrades interactive performance.  So we
>would like to be able to run some program/shell script which
>would check running jobs and if they have more than (say)
>15 minutes CPU time and (say) they are not the X server (or
>other jobs which we will allow to use as much time as they
>like) then renice them down to some lower priority level.
>
Andrew,

I wrote a cron script that I run every 15 minutes to do this.  It only
checks users that ps thinks have a terminal session.  Our undergrad
students have a account that has "xc" as the third and fourth characters
of the username.  The shell script aborts their processes with a
SIGXCPU so they know why their process died.  All processes get reniced
if they use over 5 cpu minutes of time.  The script writes to a log
file any action it takes.

>From /usr/lib/crontab:

0,15,30,45 * * * * root	/bin/sh /usr/adm/check

Here is the check script:

#! /bin/sh -
# Checking for CPU bound jobs

PATH=/usr/ucb:/bin:/usr/bin:/etc ; export PATH

/bin/ps -aug | \
/bin/awk ' { TIME = 0; TIME += substr($0,43,3) } \
	   { if (TIME > 4) { \
		print "#" $0 ; \
		printf("/etc/renice +20 %s\n",$2) }} \
	   { if (TIME > 29 && substr($1,3,2) == "xc" && $7 != "?" ) { \
		printf("/bin/kill -24 %s\n",$2) ; \
		printf("/usr/bin/sleep 5\n/bin/kill -9 %s\n",$2) }}' | \
/bin/tee -a /usr/adm/checklog | /bin/sh


-- 
Ron Nash
San Diego State University
Internet:  nash at ucselx.sdsu.edu
UUCP:      ucsd!sdsu!ucselx!nash



More information about the Comp.unix.admin mailing list