0

I was reading a separate SU question on setting ulimit value and the answer from Gordon mentioned something about hard and soft limit on open file descriptor count. Just curious, why do we need a hard and soft limit in the first place? What is the benefit behind it? Isn't it simpler just to have a singular limit without resorting to hard and soft differentiation?

By the way, I already checked the man page, and it doesn't discuss anything specific on ulimit

1
  • It could be that the distinction is carried over from the other limits where having a hard and soft limit make more sense so that the file has a regular field format.
    – Dan D.
    Apr 20, 2013 at 22:19

1 Answer 1

2

The same reason we have hard and soft limits on everything else.  The hard limit is to protect users against each other.  If one user could use resources without limit, that would diminish system performance/response for all the other users.  The soft limit is to protect users against themselves, and the open file count is the perfect example of that.  You might need to have 300 files open at once, and if your hard limit is 300 or higher, then you can do that.  (If your soft limit is below 300, then you will need to increase it –– which you can do, up to your hard limit.)  But very few programs need to have 300 files open at once.  If your program does that, it probably has a bug where it opens files and fails to close them, even if it’s done using them.  In this case, it’s probably better for you to find out about it when the program tries to open its 101st file; it will save you time, and maybe let you discover the error in your program before somebody else does.

1
  • Well, to say that hard limit is to protect users against each other is a little questionable, because you can set different hard limit count per terminal session, even under the same user account. If the purpose is to protect users from each other, I would imagine that hard limit is a number that applies to all sessions, but clearly, not quite the case? At least not under Mac. haven't verified with Linux yet.
    – Antony
    Apr 21, 2013 at 6:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .