Caveats

Things to consider, and exceptions that apply:

  • Even if one can, increasing a resource limit may do more harm than good; think through what you are trying to achieve here. Put yourself in the malicious-hacker mindset (recall (DDoS attacks). On both server class, as well as on highly resource-constrained systems (often an embedded one), setting resource limits appropriately can help mitigate risk.
  • Setting a resource limit to a higher value requires root privilege. For example: we wish to increase the max open files resource limit from 1,024 to 2,000. One would assume that using sudo should do the job. However, at first surprisingly, something such as sudo ulimit -n 2000 will not work! Why? Well, when you run it, sudo expects that ulimit is a binary executable and thus searches for it in the PATH; but of course, that's not the case: ulimit is a built-in shell command and thus fails to launch. So, try it this way:
$ ulimit -n
1024
$ sudo bash -c "ulimit -n 2000 && exec ulimit -n"
[sudo] password for kai: xxx
2000
$

Don't worry, if you don't fully understand why we use the exec in the preceding snippet; the precise details regarding exec semantics will be covered in Chapter 9, Process Execution.

  • Exception—you cannot seem to change the max pipe size resource limit.
Advanced: The default maximum pipe size is actually in /proc/sys/fs/pipe-max-size and defaults to 1 MB (from Linux 2.6.35). What if the programmer must change the pipe size? To do so, one could use the fcntl(2)system call, via the F_GETPIPE_SZ and F_SETPIPE_SZ parameters. Refer to the fcntl(2) man page for details.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset