Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With ulimit, we can find out how many open files, running processes etc. at most the user can have at the same time. My question is: how can we find out how much of these limits are being used and how much is available?

Obviously, I can count how many running processes I have, for instance. But isn't there a simpler way to do this? I assume there is a counter somewhere in the system that, when a limit is reached, the user is not allowed to use more of that resource. How could we simply print that number?

share|improve this question
The limits don't work that way. They don't have used/available semantics. (For example, say you can write checks for up to $300 each. That's your check limit. Is it sensible to ask how much of that limit is "used" or how much is "available"? These limits are those kinds of limits.) – David Schwartz Jul 17 '12 at 10:35
Okay, but I can read the check to find out where I'm situated, before or beyond the $300 limit. In linux, how can I read such number, other than counting it myself? Also, how does the system count it, since it has to compare to the user-limit, in order to stop the user from creating more sockets/processes/whatever? – Eduardo Bezerra Jul 17 '12 at 10:48
You are never beyond the $300 limit. You can't write a check over $300. There is no such thing as where you are situated, it's not that kind of limit. There is no "it" for the system to compare to the user-limit. Just like if you have a $300 check limit, there is no "it" to compare to that limit until you write a check, then the check is tested against the limit, and that's it. These are those kinds of limits. – David Schwartz Jul 17 '12 at 18:51
I see, but I still don't get your answer (sorry about that). Let me rephrase the question then: Suppose that a user derp can create only 1024 processes; currently, derp has 1024 processes, one of which is a terminal; in such terminal, derp tries to run some application (then the terminal would fork, creating another process, the application). Instead, derp gets the message fork: resource temporarily unavailable. Naturally, some other user herp could run the application with no problem. How did the system know that derp had already reached his limit? I find it hard without some counter... – Eduardo Bezerra Jul 18 '12 at 15:17
Just like when you write a check, the check is compared against the limit, when you call fork, the process table is compared against the limit. There is no counter it compares against (other than one created just for that test). If you have the Linux kernel source code handy, look at nr_processes in kernel/fork.c. – David Schwartz Jul 18 '12 at 19:17

You must log in to answer this question.

Browse other questions tagged .