How to prevent cron jobs from being run during certain times in Debian? (a 'gaming' / 'performance mode')

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.


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.