I think I have a program that creates countless forks of itself (not intentionally, I hope).
I like to test this but I can't kill the machine, so how could I limit the number of process to execute this in a sage way?
ulimit is used to temporarily establish limits to the current shell and its sons.
You can limit the number of process with
ulimit -u $desired_number
More info in
man ulimit and
e.g. User1 to 20
user1 hard nproc 20
e.g. group1 to 50
@group1 hard nproc 50