bg proccess limit

Mark Johnston mjohnston at skyweb.ca
Mon May 10 06:52:02 PDT 2004


"Coldfade" <coldfade at levkov.com> wrote:
>    i mean limit the background proccesses amount ... i work in a shell
>    providing company but can`t find suitable solution for the BSD
>    platform

This is a Simple Matter of Scripting.  Start with:

ps -x -U $THEUSER | egrep '^[0-9]+ +\?\?'

to find processes owned by THEUSER with no controlling terminal (?? in the TT 
column in ps).  You can use egrep -c to count the processes, then pipe the 
results of the same grep through tail to find some processes to kill off.  
Run that once a minute and you're set.

For a nicer fix, I'd go to Perl or Python - just run ps aux once, store the 
results into a hash of arrays (dictionary of lists) by username, then go 
through that hash/dict, comparing it to your policies, and kill off processes 
that are over the limit.

You could also use ulimit, but that will only let you limit the total number 
of processes (instead of the number of background processes.)  Still, for 
most users, the number of background processes allowed plus two or three will 
be sufficient.

HTH,
Mark


More information about the freebsd-isp mailing list