Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to know if we can use ulimit to control the maximum memory usage per process and cpu for each all the normal user on the linux system? The reason behind is i want to control the max usage of memory per user, in order to avoid the system memory and cpu highload, which will causing system hung.
I don't think there is a way to limit cpu usage as a percentage, but you can limit the amount of CPU time a user process is allowed as well as the maximum memory resident size. Instead of controlling these settings with ulimit, this is better configured by configuring /etc/security/limits.conf - especially if you want to control more than 1 user. To answer your question's specifics, here is an example of a limits.conf file trying to accomplish your goals:
Code:
@foo hard cpu 10
@foo hard rss 10240
This would limit each user (who is a member of the group 'foo') process to 10 minutes of CPU time - at which point the process would be killed. It should also limit the amount of memory a process can use to 10MB. You'll want to read the documentation that resides in the limits.conf file and make adjustments accordingly. I hope this points you in the right direction.
Thanks a lot for all the feedback. I'm thinking if control the limit, there will be the risk that it will kill the user job which reall need so much memory. Or may be i should ask if there is a way to reserve the memory and cpu resources for system process, instead of controlling at the user level.
Generally, the system processes will always have a higher priority than user processes. So when the system is 'hanging' it is the users' processes that are hanging and not the system processes that are hanging. It appears to me that you just have an overloaded system and should look into taking other action, such as:
1) Moving some users to a different server.
2) Upgrading to a server (or servers) with more and faster CPUs as well as more RAM.
I think you certainly have enough justification to take either action.
Thanks for adviced....ya, there is a lot of user session on the system. I already have 4GB memory on the system. And most of the user just running normal Xvnc and ssh session.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.