This is how to limit the maximum number of processes for a a specific user or groups in linux.
Scripts to perform this testing.
loop.sh
#! /bin/bash
x=1
while [ $x -le $1 ]
do
echo "Running timer.sh $x times";
/home/ubuntu/private/timer.sh $1&
x=$(( $x + 1 ))
done
timer.sh
#!/bin/bash
echo "Timer starts now... $1 seconds";
sleep $1;
echo "timer is done for $1 seconds:";
Before applying the limits in /etc/security/limits.conf

Let’s now set the soft and hard limit for the user ubuntu (20 and 25)

Logout then login for the settings to take effect. I am using multipass for my Ubuntu container.

Let’s test the limits!
Screenshot below shows that the user ubuntu is getting an error running the bash loop script because the max number of processes has been limited to 20.

Set limit for the group ‘testgrp’

User exception even if it’s part of the group ‘testgrp’
