1

Is it possible to limit the cpu shares for processes started from cron? Background: We have shared hosting on Centos7 and customers can make cronjobs via directadmin controlpanel. Sometimes these cronjobs eat all cpu. That's why I would like to limit the cpu for processes started by cronjobs.

I tried:

# systemctl set-property crond.service CPUShares=500

But jobs started from cron seem to go to the user.slice: /user.slice/user-1003.slice/session-283630.scope

# systemctl show session-283630.scope -p CPUShares
CPUShares=18446744073709551615

So it looks like it does not inherited the cpushares.

Is it possible to limit the cpu shares for cronjobs?

BTW: why does it show CPUShares=18446744073709551615 and not CPUShares=1024? When I check in /sys/fs/cgroup/cpu,cpuacct/user.slice/user-0.slice/cpu.shares it shows 1024:

# cat /sys/fs/cgroup/cpu,cpuacct/user.slice/user-0.slice/cpu.shares 
1024

But with systemctl is shows CPUShares=18446744073709551615:

# systemctl show user-0.slice -p CPUShares
CPUShares=18446744073709551615
Vincent
  • 291
  • 1
  • 4
  • 10

1 Answers1

0

It looks like systemd timers may be the answer to what you need, systemd-timers have native support for cgroups, more info here: https://wiki.archlinux.org/index.php/Systemd/Timers

If you must execute using cron cgexec may be the ticket, this isn't for all cronjobs, this would have to be specific to the command run in the cronjob. More info is here: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/resource_management_guide/starting_a_process