There are a few ways to do this. Sometimes you can set this in the application itself.
For example most Java apps have something like a jvm.options config file that lets you set the heap size.
The next most popular way to do this, is with containers, such as Podman or Docker.
You can also do this with ulimit.
su - someuser
ulimit -Sv 1000000
You can also set filesize limits.
ulimit -Sf 2000
The downside to doing it this way, is that every user can change their settings if they want to, (and know how).
So the method I personally use most of the time is systemd.
# This sets max memory for this app to 1G
systemd-run --scope -p MemoryLimit=1000M ./someProgram.bin
# This sets max CPU usage for this app to 10%
systemd-run --scope -p CPUQuota=10% ./anotherProgram.sh
# This does both on a same line.
systemd-run --scope -p MemoryLimit=1000M -p CPUQuota=10% ./myCoolProgram
You can do this in your systemd service file. Of course you have to be running a new enough version of Linux to support systemd. That way "normal" users can't make changes to your service startup file.
Posts and writings by Lennart Poettering
0pointer.de
If you want to limit CPU resources, you could also look at "nice"
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
www.geeksforgeeks.org