Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/5/84; site mordor.UUCP
Path: utzoo!linus!philabs!cmcl2!seismo!ut-sally!mordor!jdb
From: jdb@mordor.UUCP (John Bruner)
Newsgroups: net.unix-wizards,net.bugs.4bsd
Subject: Re: automatic renice in 4.1 bsd?
Message-ID: <6582@mordor.UUCP>
Date: Fri, 12-Oct-84 15:20:18 EDT
Article-I.D.: mordor.6582
Posted: Fri Oct 12 15:20:18 1984
Date-Received: Sat, 13-Oct-84 06:43:37 EDT
References: <170@terak.UUCP>
Distribution: net
Organization: S-1 Project, LLNL
Lines: 43

This may or may not be related to the problem posed in <170@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@mordor.ARPA [jdb@s1-c]	(415) 422-0758
  UUCP: ...!ucbvax!dual!mordor!jdb 	...!decvax!decwrl!mordor!jdb