7

Say I'm working on a sluggish system and notice (say via top) that CPU usage is up around 100%, but I don't want to kill the process. If I want to do other work on the machine and just make that process slower, can I do something like:

# nice -n -10 bash 

To get a subshell that runs commands more quickly? It doesn't seem to, so I'm curious, about what, if anything would be sped up. Builtins only? Nothing?

4
  • Just as an experiment, I did a renice to 10 for the offending process taking up 99% cpu, then ran bash under -10 niceness. Then in this shell I ran updatedb in the background and top in the foreground. The results are interesting. The offending process lists its niceness as 10, but still takes 99% cpu. A series of find commands are running now at priority 0 (default). Occasionally, top shows up at -10. So I'm guessing that interactive utilities run (at least partly) in the niceness of its parent shell. Commented Apr 23, 2015 at 15:01
  • Here's another interesting thing. I tried to renice updatedb to -15, but when it changed it, it reported that the old niceness was -10, the same as its parent shell. Apparently the find commands that updatedb is spawning do not inherit the niceness. Commented Apr 23, 2015 at 15:06
  • 1
    If you want to make another process slower, you must raise the priority. That means renice 15 $(pidof updatedb). You can also send him the STOP signal and later the CONT signal. Commented Apr 23, 2015 at 15:20
  • 1
    There's also ionice for processes that are monopolising the disk. I run my regular rsync backups with it to stop them grinding my laptop into the ground. Commented Apr 23, 2015 at 23:14

1 Answer 1

6

Negative nice values are reserved for system work. If you run a userland program with to high niceness, like -15, some kernel work that it relies on cannot run, so that the program stalls itself.

The proper way to make your system usable again is to renice the other CPU hog to higher nice values.

renice -n 5 otherpid 
2
  • This is a "nice" best practices tip, but I was asking what niceness gets inherited by commands run in a subshell invoked with a higher niceness. Commented May 7, 2015 at 14:19
  • @labyrinth Imho this is an answer. I'm explaining, that you cannot reliably improve performance by increasing the nice value of your process. Think about what happens when you write to the disk, but the kernel thread that does the job for you cannot run because its nice value is lower than that of your process. The most reliable way is to increase the niceness of other processes. Commented May 7, 2015 at 14:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.