0

Checking open files (soft) limit on current shell

/home/pkaramol
$  ulimit -n
1024

Checking hard limit

/home/pkaramol
$ ulimit -n -H
1048576

Setting (soft) limit to hard limit value and verifying it worked:

/home/pkaramol
$ ulimit -n hard
/home/pkaramol
$ ulimit -n
1048576

The question is why the following command modifies the BOTH hard and soft limits, given that when no switch is provided, the default is that operations take place on soft limit

/home/pkaramol
$ ulimit -n 2048
/home/pkaramol
$ ulimit -n 
2048
/home/pkaramol
$ ulimit -n -H
2048

At what point was the hard limit lowered to 2048 ?

3

If this is ulimit built into the bash shell, then specifying neither of -H or -S when setting a limit will set both the hard and the soft resource limits.

This is documented in the bash manual:

ulimit [-HSabcdefiklmnpqrstuvxPT [limit]]

Provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The -H and -S options specify that the hard or soft limit is set for the given resource. A hard limit cannot be increased by a non-root user once it is set; a soft limit may be increased up to the value of the hard limit. If neither -H nor -S is specified, both the soft and hard limits are set.

The ksh93 shell has a similar wording in its manual,

If neither the H nor S option is specified, the limit applies to both.

... and the zsh and dash shells also behaves the same with regards to setting the limits.

  • This is a reason why bosh implements the BSD limit builtin as well since the BSD interface is more intuitive. – schily Oct 27 '18 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.