0

I just learned the existence of nice (and ionice) which seems to be really interesting.

I just want to launch a process 'p_low' with less priority than my ususal one 'p_normal'.

What I was able to get from the wiki page (only source which shows me how the resource is distributed), is that:

a process run with nice +15 will receive 25% of the CPU time allocated to a normal-priority process: (20 − 15)/(20 − 0) = 0.25

So based on that I can provide 10% of the CPU time to my p_low process if "nice -18 p_low"

This is perfect IF MY 'p_normal' IS RUNING.

So question: is there a way to tell the scheduler to use the default niceness value, and only -18 when there is something else running?

In the worst case I can make a script which check if anything else is running, and "renice" my process, but it doesn't seem to be the best option to me...


EDIT:

ANSWER: As pointed out by @jilliagre in the comments below his answer:

if nothing else is running the command will get 100% of the CPU whatever the niceness given (-18, 0, +18, ...)

0

You are missing how nice works. It is simply a hint to the scheduler for it to prioritize some processes against others when there is a CPU bottleneck.

I there is nothing else running, whatever its niceness, your process will be granted all the CPU power so there is no need to change the niceness in that specific case.

  • @jilliagre, so I can basically simply launch my low priority script (p_low) with 'nice -18', right? -- if anything else run, it will allocate the full CPU power? – Bast Feb 2 '16 at 12:45
  • nice -n -18 will make your process a high priority one, not low priority. Note that you'll need to be root to increase the priority. You probably want nice -n 18 command ... which will indeed leave more power to potential competing processes. – jlliagre Feb 2 '16 at 13:03
  • @jilliagre, running 'nice -n 18' === 'nice -18' based on this page: thegeekstuff.com/2013/08/nice-renice-command-examples ... – Bast Feb 2 '16 at 13:12
  • so basically, if I run 'nice -18 COMMAND' (OR 'nice -n 18'), would it execute COMMAND with 100% of the CPU time if nothing else is running? – Bast Feb 2 '16 at 13:13
  • As already answered, if nothing else is running the command will get 100% of the CPU whatever the niceness given (-18, 0, +18, ...) – jlliagre Feb 2 '16 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.