It depends if you want to use it on user level or system level. On user level the ulimit
(or corresponding commands for other shells) would be easiest solution.
However on system level there are mechanisms to prevent malicious users (or just not using ulimit) from stopping the system. Linux cgroups mechanism can limit the resources on per-group basis. You can force (by pam_systemd
machanism) the user session to be in specific group. This have other benefits for, for example, CPU scheduler.