Linux resource limits can stop an application from using more CPU time or memory than intended. For an application managed by systemd, you can set limits on its service and the processes that service starts.
Identify the service
You need administrator access on a system with the required systemd resource controllers enabled. Find the actual service name and record its existing configuration:
systemctl status example.service
systemctl cat example.serviceReplace example.service throughout this guide with the intended service. A service limit applies to its process group, not just one selected process ID.
Set CPU and memory limits
Create or edit the service’s override:
sudo systemctl edit example.serviceAdd settings appropriate for that application. For example:
[Service]
MemoryMax=500M
CPUQuota=30%Here, 30% means 30% of the CPU time available on one CPU core. It does not mean 30% of the server’s total CPU capacity.
An application that exceeds its memory limit may have processes terminated by the operating system. Choose limits from measured usage and test them before restricting a live service.
Apply and verify the limits
Save the override, then apply it during a suitable maintenance window:
sudo systemctl daemon-reload
sudo systemctl restart example.service
systemctl show example.service -p MemoryMax -p CPUQuotaPerSecUSec
systemctl status example.serviceRestarting interrupts that service. Check its logs and application behaviour afterwards. If the limits cause failures, adjust or remove only the settings you added, reload the configuration and restart again.
Understand other tools
nice and renice change scheduling priority; they do not impose a fixed CPU cap. Tools such as cpulimit can restrict a selected process temporarily, but they do not provide the same persistent service-group control.