`nice' issues revisited

Darrell Kindred (dkindred@cmu.edu)
Fri, 23 May 1997 18:31:15 -0400

I have a correction to my previous instructions on running
deschall nicely under Unix. It turns out that the AIX
scheduler will give as much as 33% of the CPU to a nice=19
process when it's competing with a cpu-hungry nice=0 process.

This annoying behavior can be overcome, though. If you
save the program below as verynice.c and compile it with

cc -o verynice verynice.c

Then you can run the following as root:

./verynice deschall keymaster.verser.frii.com

This will give deschall a fixed, extremely low priority.
Under these conditions, deschall will get no CPU cycles at
all if a normal process wants the CPU. If you're nervous
about running it as root, you can use 'su' as shown below.

So, to summarize, use the commands below to make deschall as
nice as possible. (Replace 'deschall' with the appropriate
client executable.)

npri -h 150 deschall keymaster.verser.frii.com

cc -o verynice verynice.c
then, as root:
./verynice su someuser -c deschall keymaster.verser.frii.com

HPUX, SunOS, Solaris:
/bin/nice -19 deschall keymaster.verser.frii.com

Linux, NetBSD:
/usr/bin/nice -n 19 deschall keymaster.verser.frii.com

I've tested the commands above under each of the listed
operating systems. For all systems except Solaris & NetBSD,
deschall uses only 0-8% of the CPU when a normal-priority
cpu-hungry process is running. Under Solaris, deschall gets
about 10-15%. Under NetBSD, it gets about 25%.

It might be good to put this info in the FAQ.

- Darrell

/* verynice.c -- run a command at the lowest possible priority, under AIX */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/sched.h>
#include <errno.h>

/* not declared in AIX headers--sigh */
int setpri (pid_t ProcessID, int Priority);

void usage ()
fprintf (stderr, "usage: verynice <command> [args]\n");

int main (int argc, char *argv[])
int niceness;

if (argc < 2)
usage ();
exit (1);

if ((niceness = nice (20)) < 0)
perror ("verynice: warning: nice(40) failed");

if (setpri (0, PRI_LOW) < 0)
switch (errno)
case EPERM:
fprintf (stderr, "verynice: setpri failed: not root\n");
perror ("verynice: setpri failed");
fprintf (stderr, "verynice: WARNING: running at niceness %d"
" instead of fixed low priority\n", niceness);

execvp (argv[0], argv);

fprintf (stderr, "can't run `%s'\n", argv[0]);
usage ();
exit (1);