8

Notes: 1. by lower priority I mean that the priority number is lower. 2. Distro is RHE

I want to start a daemon with lower than normal priority (ie. say 18 rather than 20) so it will get cpu first in the case of contention.

nice runs commands at increased priority, renice can raise or lower but works for processes that are already running.

I would rather not have to dig the pid out of the process list and then call renice in the start script if I can avoid it since the program does not conveniently produce a pid file.

Jenny D
  • 27,358
  • 21
  • 74
  • 110
Russell Fulton
  • 159
  • 1
  • 2
  • 14
  • Which major RHEL release, 6 or 7? – HBruijn Oct 18 '16 at 02:27
  • Are you really that CPU constrained at this point? You should be careful of this type of design because there may be unintended consequences. – ewwhite Oct 18 '16 at 03:00
  • What @HBruijn said. – Michael Hampton Oct 18 '16 at 03:07
  • yes, I'm aware of the dangers. In this case I have a daemon (radium) that collects data over the network and every hour compresses the last hours data. The compress jobs were hogging the cpu and I was loosing data because radium is not reading it fast enough. I am keeping an eye on it to make sure the compress jobs finish before the next run ;) – Russell Fulton Oct 18 '16 at 22:29

2 Answers2

12

You just launch it with nice.

E.g.:

nice -n 18 /path/to/mydaemon

dmourati
  • 24,720
  • 2
  • 40
  • 69
  • Ah Thanks! that works fine. I was mislead by man page that states: -n, --adjustment=N add integer N to the niceness (default 10) where as it seems not to reflect reality ??? This whole thing with "niceness" and "priority" is confusing – Russell Fulton Oct 18 '16 at 22:20
4

Additionally, you can use the ionice command to start the process with low io priority:

nice -n18 ionice -c3 /path/to/mydaemon