How to find ulimit for users on Linux

How can you find the ulimit value for a user account or a process on a Linux system?

To work properly, we must ensure that the correct ulimit values ​​are set after installing different software. Linux systems provide means to limit the amount of resources used. Each Linux user account has its own set of limits. The limit system is applied individually to each user's process. For example, if a certain threshold is too low, the system cannot host websites using Nginx / Apache or PHP / Python applications. Restrict system resources viewed or set by the NA command. Let's find out how to use ulimit to provide control over the resources available to shells and processes.

Picture 1 of How to find ulimit for users on Linux
The ulimit values ​​on Linux

How to find ulimit for users on Linux

Linux ulimit command sets or displays user process resource limits. Typically, the limits are found in /etc/security/limits.conf or systemd.

Two types of limits

All Linux limits are divided into two categories:

  1. Soft limit : All users can change the soft limit, up to the hard limit. Change to -S for ulimit.
  2. Hard limit : Only root users are allowed to change hard limits. Change to -H for ulimit.

See the ulimit for Linux user accounts

Enter the following command to view all soft and hard limits for the current user:

ulimit -Sa ## Show soft limit ## ulimit -Ha ## Show hard limit ##
core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 126787 max locked memory (kbytes, -l) 65536 max memory size (kbytes, -m) unlimited open files (-n) 1048576 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) unlimited cpu time (seconds, -t) unlimited max user processes (-u) 126787 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

List all hard ulimit for user named 'tom'

You must run the following command as root user or at least have access to that account via sudo / su:

su - tom -c "ulimit -Ha" su - tom --shell /bin/bash -c "ulimit -Ha" ## You can use the sudo command ## sudo -u tom bash -c "ulimit -Ha" sudo -u tom sh -c "ulimit -Ha"

Find all soft ulimit for user named 'jerry'

Do the above again:

su - jerry -c "ulimit -Sa" su - jerry --shell /bin/sh -c "ulimit -Sa" ## You can use the sudo command ## sudo -u jerry bash -c "ulimit -Sa" sudo -u jerry sh -c "ulimit -Sa"

Search for 'ulimit-a' for process user

A Linux process is the running version of a program. For example, when you start the Firefox application, you created a process. However, some processes have been running in the background for quite some time. Normally, with background running, you cannot use the sudo or su command to find their limits. Here, nginx is running as www-data user on Debian Linux, but the shell is blocked from accessing the www-data user account by default for security reasons. In other words, the following su / sudo command will fail 100%.

$ su - www-data -c "ulimit -Sa" This account is currently not available.

How to find ulimit for a process

Recipe:

cat /proc/PID/limits

First find the PID (process ID) for nginx, run ps with grep:

ps aux | grep nginx

 

Example results:

root 8868 0.0 0.0 127044 24048 ? Ss May23 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; www-data 18074 0.0 0.0 127276 24716 ? S May23 0:09 nginx: worker process www-data 18075 0.0 0.0 127276 22284 ? S May23 0:00 nginx: worker process

Now type the cat command:

cat /proc/8868/limits

Example results:

Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes unlimited unlimited processes Max open files 1024 1048576 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 385944 385944 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us 

Most programmers and sysadmin need to know the maximum number of processes and open files per nginx process. In a nutshell, we find the PID using 'ps aux | grep appname ', then look for the' limits' files of that PID in / proc /. Then you will know for sure which values ​​to apply to adjust performance.

Update 19 June 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile