[comp.unix.admin] Program to renice jobs

andrew@granada.mit.edu (Andrew Gunstensen) (10/19/90)

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.

Any thoughts on this?  Is it even desirable to do this?

Thanks for any info.

--
Andrew Gunstensen                                         _  /\
Rm 54-616, MIT, Cambridge, MA 02139, (617)-253-3384       \'o.O'     Bill
Internet: andrew@segovia.mit.edu                          =(___)=    Rules
                                                             U
      Data?  I don't need no stinkin' data!                      ack!

wsinpdb@svin02.info.win.tue.nl (Paul de Bra) (10/19/90)

In article <1990Oct19.094659@granada.mit.edu> andrew@granada.mit.edu (Andrew Gunstensen) writes:
>Is there a good method of renicing jobs automatically once they
>have exceeded some CPU time limit?

Funny, while i worked at the univ of Antwerp, our Gould system
with Utx/32, which was based on BSD4.2, had this built into the kernel.
All jobs would automatically be niced after using some amount of
cpu-time.

I presume other manufacturers took that code out because more and more
programs legitimately use a lot of cpu-time (nfs deamons, X-server,
GNU-emacs, etc)

Maybe it's still in the source code, albeit commented out.
Then you can go look for it and put it in again. But as far as i know
there is no code to allow for exceptions, unless owned by root.

Paul.
(debra@research.att.com)

nash@ucselx.sdsu.edu (Ron Nash) (10/20/90)

In article <1990Oct19.094659@granada.mit.edu> andrew@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@ucselx.sdsu.edu
UUCP:      ucsd!sdsu!ucselx!nash

eloranta@tukki.jyu.fi (Jussi Eloranta) (10/20/90)

In article <1990Oct19.173229.16217@ucselx.sdsu.edu> nash@ucselx.sdsu.edu (Ron Nash) writes:
>In article <1990Oct19.094659@granada.mit.edu> andrew@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.
>>

Look into anon. ftp area @ jyu.fi (/pub/local) there should reallynice.c.Z
That should do the job. This should work with sunos 4.0 without any problems.

Jussi


-- 
============================================================================
Jussi Eloranta               Internet(/Bitnet):
University of Jyvaskyla,     eloranta@tukki.jyu.fi
Finland                      [128.214.7.5]