Hot answers tagged

124

Another way to limit this is to use Linux's control groups. This is especially useful if you want to limit a process's (or group of processes') allocation of physical memory distinctly from virtual memory. For example: cgcreate -g memory:myGroup echo 500M > /sys/fs/cgroup/memory/myGroup/memory.limit_in_bytes echo 5G > /sys/fs/cgroup/memory/myGroup/...


116

No but you should close all active sessions windows. They still remember the old values. In other words, log out and back in. Every remote new session or a local secure shell take effect of the limits changes.


89

Shell Session Limit The limits set via ulimit only affects processes created by the current shell session. The "soft limit" is the actual limit that is used. It could be set, as far as it's not greater than the "hard limit". The "hard limit" could also be set, but only to a value less than the current one, and only to a value not less than the "soft ...


85

You probably have a Linux distro that uses systemd. Systemd creates a cgroup for each user, and all processes of a user belong to the same cgroup. Cgroups is a Linux mechanism to set limits on system resources like max number of processes, CPU cycles, RAM usage, etc. This is a different, more modern, layer of resource limiting than ulimit (which uses the ...


79

A hard limit can only be raised by root (any process can lower it). So it is useful for security: a non-root process cannot overstep a hard limit. But it's inconvenient in that a non-root process can't have a lower limit than its children. A soft limit can be changed by the process at any time. So it's convenient as long as processes cooperate, but no good ...


64

The mappings of systemd limits to ulimit Directive ulimit equivalent Unit LimitCPU= ulimit -t Seconds LimitFSIZE= ulimit -f Bytes LimitDATA= ulimit -d Bytes LimitSTACK= ulimit -s Bytes LimitCORE= ulimit -c Bytes LimitRSS= ulimit -m ...


39

According to the kernel documentation, /proc/sys/file-max is the maximum, total, global number of file descriptors the kernel will allocate before choking. This is the kernel's limit, not your current user's. So you can open 590432, provided you're alone on an idle system (single-user mode, no daemons running). Note that the documentation is out of date: ...


36

Apply the changes directly to a running process if you have prlimit installed (comes with util-linux-2.21) prlimit --pid <pid> --<limit>=<soft>:<hard> for example prlimit --pid 12345 --nofile=1024:2048 Refer here


33

That is certainly not trivial task that can't be done in userspace. Fortunately, it is possible to do on Linux, using cgroup mechanizm and its blkio controller. Setting up cgroup is somehow distribution specific as it may already be mounted or even used somewhere. Here's general idea, however (assuming you have proper kernel configuration): mount -t tmpfs ...


29

A process can change its limits via the setrlimit(2) system call. When you run ulimit -n you should see a number. That's the current limit on number of open file descriptors (which includes files, sockets, pipes, etc) for the process. The ulimit command executed the getrlimit(2) system call to find out what the current value is. Here's the key point: a ...


29

To temporarily set the open files limit for the user you are currently logged in under (e.g. 'root'):You can also use the ulimit command to change the values in your current shell. However, hard limits can only be adjusted downwards unless you're root. Example: # ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) ...


22

ionice from the util-linux does something similar to what you want. It doesn't set absolute IO limits, it sets IO priority and 'niceness' - similar to what nice does for a process' CPU priority. From the man page: ionice - set or get process I/O scheduling class and priority DESCRIPTION This program sets or gets the I/O scheduling class and priority ...


22

Maybe this helps for the first question: If you know the process IDs (PID) of the specific user you can get the limits for each process with: cat /proc/<PID>/limits You can get the number of opened files for each PID with: ls -1 /proc/<PID>/fd | wc -l And then just compare the value of Max open files with the number of open file descriptors ...


21

To change the limits of a running process, you may use the utility command prlimit. prlimit --pid 12345 --nofile=1024:1024 What that does internally is to call setrlimit(2). The man page of prlimit should contain some useful invocation examples. Source: https://sig-io.nl/posts/run-time-editing-of-limits-in-linux/


16

Limits are inherited from a parent process to its child processes. Processes running as root can change limits arbitrarily; other processes cannot increase hard limits. Thus the hard limits set by the login process affect all the processes in a session. If you change /etc/security/limits.conf, this will affect all new sessions, and processes in these new ...


16

Let us understand the difference between a process and a thread. As per this link, The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces. Now, we have the pid_max parameter which can be determined as below. cat /proc/sys/kernel/pid_max So the above command returns 32,...


15

It is Important to know that there are two kinds of limits: A hard limit is configurable by root only. This is the highest possible value (limit) for the soft limit. A soft limit can be set by an ordinary user. This is the actual limit in effect. Solution for a single session In the shell set the soft limit: ulimit -Sn 2048 This example will raise the ...


15

On Linux you can configure it via limits.conf, e.g. via # cd /etc/security # echo debian-transmission - nofile 8192 > limits.d/transmission.conf (which sets both the hard and soft limit for processes started under the user debian-transmission to 8192) You can verify the change via: # sudo -u debian-transmission bash -c "ulimit -a" [..] open files ...


14

Increase max number of ulimit open file in Linux 1.Step : open the sysctl.conf and add this line fs.file-max = 65536 $ vi /etc/sysctl.conf add new line and fs.file-max = 65536 save and exit. 2.Step: $ vi /etc/security/limits.conf and add below the mentioned * soft nproc 65535 * hard nproc 65535 * soft nofile ...


13

This won't crash modern Linux systems anymore anyway. It creates hoards of processes but doesn't really burn all that much CPU as the processes go idle. You run out of slots in the process table before running out of RAM now. If you're not cgroup limited as Hkoof points out, the following alteration still brings systems down: :(){ : | :& : | :& }; ...


12

I think the confusion comes from the fact that the underlying system call that ulimit wraps is called setrlimit. excerpt from the ulimit man page The ulimit() function shall control process limits. The process limits that can be controlled by this function include the maximum size of a single file that can be written (this is equivalent to using ...


12

Try to change UsePAM yes on UsePAM no in /etc/ssh/sshd_config (for CentOS)


11

To make this change pervasive you'll need to add these limits to the entire environment. Changes using the ulimit command are only to the current environment. NOTE: This will have no effect on the root user! Example Edit this file: vi /etc/security/limits.conf and add entries to the file limiting the number of processes (nproc) that a specific user or ...


11

On any systemd-based distro you can also use cgroups indirectly through systemd-run. E.g. for your case of limiting pdftoppm to 500M of RAM, use: systemd-run --scope -p MemoryLimit=500M pdftoppm Note: this gonna ask you for a password but the app gets launched as your user. Do not allow this to delude you into thinking that the command needs sudo, because ...


11

It seems that creating the file /etc/launchd.conf and putting your command inside it should do the trick. If it does not work, you can probably edit or create the /etc/rc.local file and add your command inside it as there is little chance that Apple will ever delete support for limit on the command line. Edit 1: I should have start with that, the ...


11

It says right there in the article: This has no effect on Linux. man setrlimit says it used to work only in ancient versions. The setrlimit man page says: RLIMIT_RSS Specifies the limit (in pages) of the process's resident set (the number of virtual pages resident in RAM). This limit has effect only in Linux 2.4.x, x < 30, ...


11

Sorry, the accepted answer is bad information on several fronts. /proc/sys/kernel/pid_max has nothing to do with the maximum number of processes that can be run at any given time. It is, in fact, the maximum numerical PROCESS IDENTIFIER than can be assigned by the kernel. In the Linux kernel, a process and a thread are one an the same. They're handled ...


10

Output the current user's percentage of open files, proc, and pending signals, by several inconvenient methods and standard tools: paste <(grep 'open files\|processes\|pending signals' /proc/self/limits | cut -c27-38) \ <(i=`whoami` ; lsof -u $i | tail -n +2 | awk {'print $9'} | wc -l; ps --no-headers -U $i -u $i u ...


10

https://superuser.com/questions/1200539/cannot-increase-open-file-limit-past-4096-ubuntu/1200818#= There's a bug since Ubuntu 16 apparently. Basically: Edit /etc/systemd/user.conf for the soft limit, and add DefaultLimitNOFILE=1048576. Edit /etc/systemd/system.conf for the soft limit, and add DefaultLimitNOFILE=2097152. Credit goes to @mkasberg.


9

Use pam_limits(8) module and add following two lines to /etc/security/limits.conf: root hard nofile 8192 root soft nofile 8192 This will increase RLIMIT_NOFILE resource limit (both soft and hard) for root to 8192 upon next login.


Only top voted, non community-wiki answers of a minimum length are eligible