Resouce(CPU & RAM) management in Linux?

I want restrict the usage of CPU & RAM for individual users. Becouse, if an user (like me) have a simple login to a server (may be remotely) and if he/she runs a program like followings:

main()
{
      for(;;)
        fork();
}

And it will anough to make a server HANG for ever, the only way to Hard boot, and stop&restart the server.
Is there any way to restrict the resources for individual users??
TigreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

edicomCommented:
Well I had a malloc before the fork to have more fun (tried just that once on a dual pentium box)
I d say you could have a look at the ulimit command of the shell, and then probably you ll have to use it in a global shell config file (/etc/bashrc /etc/profile or something of the kind).
I guess if you want to use per users limits. Else for general limits see the /proc/sys filesystem (/usr/src/linux/Documentation/sysctl).
Regards,
0
TigreAuthor Commented:
From shell level it is not possible to restrict an USER. We have to think about some demon process which will look after user's request and fork some process to take the control from user incase of any WRONG resource handling.. If this type of sol. is already available Please inform me....
It self in UNIX (or like) their is no provision to resist an user who have the execution permission (of vi, cc etc) on shell.
If i am wrong, pl. inform me...
0
j2Commented:
*BSD (FreeBSD, NetBSD, OpenBSD) have this type of quota (max mem, max cpu etc etc etc) built in. Linux does not.

If there is anything like this for linux, it is prolyy called "BSD Style Quota" or something.
0
mixerfix122699Commented:
You can set upper limits for resource usage by the ulimit bash-builtin, setting it in the /etc/profile.

Sorry for the long example...

e.g.

In my /etc/profile, I have `ulimit -c 100` (which limits my core size to 100 blocks).

balk:~# ulimit -a
core file size (blocks)     100
data seg size (kbytes)      unlimited
file size (blocks)          unlimited
max locked memory (kbytes)  unlimited
max memory size (kbytes)    unlimited
open files                  1024
pipe size (512 bytes)       8
stack size (kbytes)         8192
cpu time (seconds)          unlimited
max user processes          256
virtual memory (kbytes)     unlimited
balk:~# su - marc

balk:/amd/balk/home/marc$ ulimit -a
core file size (blocks)     100
data seg size (kbytes)      unlimited
file size (blocks)          unlimited
max locked memory (kbytes)  unlimited
max memory size (kbytes)    unlimited
open files                  1024
pipe size (512 bytes)       8
stack size (kbytes)         8192
cpu time (seconds)          unlimited
max user processes          256
virtual memory (kbytes)     unlimited
balk:/amd/balk/home/marc$ ulimit -c 666
su: ulimit: cannot modify limit: Operation not permitted

balk:/amd/balk/home/marc$ ulimit -c 50
balk:/amd/balk/home/marc$ ulimit -a
core file size (blocks)     50
data seg size (kbytes)      unlimited
file size (blocks)          unlimited
max locked memory (kbytes)  unlimited
max memory size (kbytes)    unlimited
open files                  1024
pipe size (512 bytes)       8
stack size (kbytes)         8192
cpu time (seconds)          unlimited
max user processes          256
virtual memory (kbytes)     unlimited

The same goes for '-u' flag....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
edicomCommented:
Well seems just what I said about ulimit, just in more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.