By default, all commands typed at the Linux command-line run at interactive user-interface priority. To share a multi-user machine politely, you should set a lower priority for your long-running jobs so that others still get good interactive response when they are typing.
- priority is set in terms of a nice value
- the default interactive priority has a nice value of zero
-
a
job
that
runs
at
a
high
priority
is
less
polite,
or
less
nice,
so
it
has
a
negative
nice
value
- you cannot set your job to run with a negative nice value (higher priority than the default)
-
a
job
that
runs
at
a
lower
priority
is
more
polite,
or
more
nice,
so
it
has
a
positive
nice
value
- you can set your job to run with a positive nice value
- the range of nice values is from 0 to 20, so 20 is the most nice, i.e. the lowest priority
-
to
start
a
job
at
a
nice
priority,
put
the
keyword
nice
and
the
desired
priority
at
the
start
of
the
command,
e.g.
-
nice 15 ./my-long-job &
-
-
use
the
ps
command
to
get
a
list
of
your
processes
along
with
their
process
ID
(PID)
and
nice
value,
and
the
renice
command
to
change
the
niceness
of
a
job
that's
already
running
-
the
renice
command
takes
a
new
nice
value
and
the
PID
of
the
job
you
want
to
modify.
Suppose
your
userid
is
jtkirk:
% ./a.out & % ps -u jtkirk -o pid,nice,cmd PID NI CMD 4784 0 sshd: jtkirk@pts/41 4786 0 -bash 8499 0 ./a.out % renice 15 8499 % ps -u jtkirk -o pid,nice,cmd PID NI CMD 4784 0 sshd: jtkirk@pts/41 4786 0 -bash 8499 15 ./a.out
-
the
renice
command
takes
a
new
nice
value
and
the
PID
of
the
job
you
want
to
modify.
Suppose
your
userid
is
jtkirk: