2

This is very odd. I'm trying to set the ulimit to 60000 via my startup.sh:

#!/bin/bash

ulimit -n 60000
echo "Hello! File Descriptor set"

I can execute this with ./startup.sh (755 file permissions) and the echo line is printed, and no errors are shown. However, when I do ulimit -n it still shows 1024, what's going on?

What I also find fascinating is I can type ulimit -n 60000 in the terminal, and then do ulimit -n and it works perfectly. Why can't I set the file descriptor limit through a script?

Debian 8, 64-bit. OpenVZ Container

2 Answers 2

0

That's simply because the limit was set inside the shell script i.e. the shell (bash in this case) spawned by executing the script (kernel actually puts the script as an argument to the shell).

So, once the script execution is done, that shell is gone (and the limit) too. And you're back to your original shell.

To test, run the ulimit -n inside the script.

3
  • I see. Kept thinking it was a global setting or something, thank you for clearing that up! Jan 26, 2018 at 21:14
  • @JohnMiller If you are not willing to craft something up, and happy with user/group based limits, see /etc/security/limits.conf (used by pam_limits).
    – heemayl
    Jan 26, 2018 at 21:20
  • Oh sweet. Will definitely use that instead. (cant upvote, but pretend I did :)) Jan 26, 2018 at 21:21
0

Processes can only set limits for themselves and their children; what you're trying to set with ulimit -n is a global limit, not a per-process one. In order to set global limits as you desire, you could create a Python script using setrlimit() and resource.RLIMIT_NOFILE from the resource module.

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.