automatic renice in 4.1 bsd?

John Bruner jdb at mordor.UUCP
Sat Oct 13 05:20:18 AEST 1984


This may or may not be related to the problem posed in <170 at terak>,
but it is a bug in all of the versions of "csh" I've seen (3BSD,
4BSD, 4.1BSD, 4.2BSD).

The C shell is supposed to interpret the command

	% nice +n

as a directive to change its own "niceness" to "n" (where "n" is 4
by default).  However, the sequence that it uses to do this
(in "sh.time.c", routine donice()) is [essentially]

	nice(20);
	nice(-10);
	nice(4);

Thus, if you are "root" your "nice" is raised by 20, lowered by 10,
and then raised by 4.  Assuming that you started at 0 you are now
at 13 (since it "pegs" at 19).

If you aren't lucky enough to be "root", your "nice" is raised by
20, then it is raised by 4 more (negative "nice" requests are ignored
for non-super-users).  Thus, if you started at 0 you are now at 19.

The reason for this lossage is the fact that nice() originally was
absolute (e.g. "nice(4)" set your niceness to 4), but now (since V7)
it is relative.

The solution depends upon the version of UNIX you are running.  On
4.2BSD nice() is just a subroutine and you can replace the sequence
of calls to it with a single setpriority().  I'm not sure that there
is a correct solution on other versions of UNIX (except V6, of course)
unless your version of nice() returns the current "niceness".  In
any event, you should remove the extraneous "nice(20); nice(10);"
(which would be wrong even if ordinary mortals were allowed to
reduce their "niceness").

I'll resist the temptation to flame about the syntax of "csh"'s
"nice" versus "/bin/nice".
-- 
  John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
  MILNET: jdb at mordor.ARPA [jdb at s1-c]	(415) 422-0758
  UUCP: ...!ucbvax!dual!mordor!jdb 	...!decvax!decwrl!mordor!jdb



More information about the Comp.unix.wizards mailing list