1

What benefit is there in specifying "-" for limit type versus specifying "hard?"

The man page for limits.conf on CentOS says of the limit type, "hard ... The user cannot raise his requirement of system resources above such values" and "soft ... These limits are ones that the user can move up or down within the permitted range by any pre-existing hard limits."

It sounds like hard is simply more restrictive than soft, so how does specifying both, with "-", make any sense? It's as if you're saying both, "user can't change this" and "user can change this."

FWIW, I'm trying to reduce and restrict the default nice for user logins. I'm currently using * - priority 15 but wondering how that is any different from * hard priority 15.

plong
  • 127

1 Answers1

4

The - is there to allow you to set the hard and soft limits in three ways:

  1. Specifying a hard limit, without touching any soft limit that is beneath that already.
  2. Specifying a soft limit within the range of zero and the hard limit.
  3. Specify both and thus setting the soft limit to its maximum.

The third option would not be possible without - if the default of a soft limit was beneath that of the hard limit.

In the case of priority it seems that the number is just the niceness value to run user processes at. A user can't renice a process to a lower value in any case so I'm not sure how to interpret "hard" and "soft" limits at all (and I'm not on a Linux system where I may test this).

Kusalananda
  • 333,661
  • Thanks for your answer, but I still don't understand. I guess the problem is that I don't know what hard and soft limits are, even after much googling. I take it that a user cannot further liberalize a resource limit past its hard limit. That's simple enough. But what's a soft limit? Is that merely the initial value of a limit? For example, if I use "mark - priority 15," does that set mark's initial nice value to 15 and prevent mark from setting it to a lower value (setting it higher is okay)? Is it that simple? – plong Aug 03 '16 at 17:52
  • @plong The soft limit is the value of the limit right now, for this process. The hard limit is the upper bound for the soft limit. I set a soft limit of 0 (zero) for core file creation. If I want to create a core file for a segfaulting program I'm debugging, I raise it before running the program. – Kusalananda Aug 03 '16 at 17:58
  • @plong I've never used this for the niceness value. You may have to just experiment with it. A user may not change the niceness to a lower value in any case, regardless of its initial setting. – Kusalananda Aug 03 '16 at 18:00