[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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??
0
Tigre
Asked:
Tigre
1 Solution
 
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
 
edicomCommented:
Well seems just what I said about ulimit, just in more details.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now