It looks like I have logcheck set up as a cron job and whenever it's run process grep by logcheck takes up around ¼ of my CPU.

Now I have certain times during which I need my full CPU capacity and have my system take up fewest resources as possible except for specific/processes (which I maybe could specify somehow).

Is it possible to set my Debian 9.1 with KDE machine into some sort of performance mode (or 'Gaming mode') that prevents processes not explicitly started by the user from taking up much system resources, lowers the load of background-processes and most importantly: delays cron jobs until that mode is stopped again?

  • 6
    A simple solution would be not to run logcheck in the cron job, but instead to write a custom script and run that in the cron job. In the script, first perform whatever checks you need and then run logcheck at the end of the script if those checks all pass. – SauceCode Sep 4 '17 at 10:57
  • 5
    Check the priority. If it has been niced down to 19 it only runs when the cpu has nothing else to do. – Thorbjørn Ravn Andersen Sep 5 '17 at 6:30

If “certain times” aren’t fixed, i.e. you want to specify manually when your system enters and leaves “performance mode”, you can simply stop and start cron:

sudo systemctl stop cron

will prevent any cron jobs from running, and

sudo systemctl start cron

will re-enable them.

You could also check out anacron instead of cron, it might be easier to tweak globally in a way which would fit your uses.

| improve this answer | |

I would consider two approaches

  1. Leave the scheduling untouched but run all cron jobs under nice, and possibly even ionice:

    0 * * * *    root    ionice -c3 nice /some/command and parameters
  2. Disallow any cron jobs during certain times. Remember that any user who can create (or remove) the flag file can control this approach. That might work if you want to have a gaming mode that is set up on demand, by adding the touch and rm commands to your game's start-up script. (You might need to use /tmp rather than /var/run, but then it's trivially open to any user.)

    0 18 * * *      root    touch /var/run/no_cron
    0 19 * * *      root    rm -f /var/run/no_cron
    0 * * * *       root    test ! -f /var/run/no_cron && /some/command...

Once set up, neither approach requires root access. Moreover you can decide in advance which jobs should be subject to this control, and which must not.

| improve this answer | |
  • 1
    Correct. Why bottleneck a process when there is plenty of CPU available? OS priorities kick in when there's a scarcity, not arbitrarily. – MSalters Sep 4 '17 at 13:36
  • I don't believe the -c3 -n7 combination makes sense, at least on Linux. The idle scheduling class has no priorities. – gardenhead Sep 5 '17 at 5:32
  • @gardenhead oops you're right. I use -c2 -n7 myself but when I dropped the class to idle for this answer I omitted to remove the priority. – roaima Sep 5 '17 at 6:43

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.