Linux limit process number

Maximum number of processes in linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.

What is the maximum limit to the number of processes possible in a linux system? How can we find it ?

Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask.

5 Answers 5

Your kernel should export this information in procfs :

This is the maximum number of unique process identifiers your system can support.

Since it is a file, /proc/sys/kernel/pid_max can be inspected from any capable programming language.

this may be true, but in most nice distros this is limited by /etc/security/limits.conf which can filter max number of processes on user/group/domain basis.

ulimit might limit the max per-user processes to less than the maximum pid, and from a bit of Googling, there’s other limitations in play as well (but I couldn’t find any definitive sources to confirm, such as LKML or a well known Dev posting it).

As suggested by Ninefingers.

For completeness, you can change it temporarily by writing to /proc/syskernel/pid_max or permanently by adding:

to /etc/sysctl.conf. 4194303 is the maximum limit for x86_64 and 32767 for x86.

The actual maximum is 32768 on 32 bit kernels, and 4194304 on 64 bit. However the maximum PID you will see is 1 less. See: unix.stackexchange.com/a/162105/23450

Short answer to your question : Number of process possible in the linux system is UNLIMITED.

Читайте также:  Canon 3228 драйвер linux

But there is a limit on number of process per user(except root who has no limit).

And you can check your user limits with below command (apposite to «max user processes»).

$ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 256447 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 128000 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 500000 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited 

If you want to increase the limit on number of process for a particular user(for eg: hadoop ) , you need to make below entry in /etc/security/limits.conf

Источник

How to Set Limits on User Running Processes in Linux

One of the Linux’s beauties is that you can control almost everything about it. This gives a system administrator a great control over his system and better utilization of the system resources.

While some might have never thought about doing this, it is important to know that in Linux you can limit how much resource a single user may use and for how long.

In this short topic, we will show you how to limit the number of processes started by user and how to check the current limits and modify them.

Before we go any further there are two things we need to point:

  1. You need root access to your system to modify the user limits
  2. You must be extremely careful if you plan to modify these limits

To setup user limits, we will need to edit the following file:

This file is used to apply ulimit created by the pam_module.

The file has the following syntax:

Here we will stop to discuss each of the options:

  • Domain – this includes usernames, groups, guid ranges etc
  • Type – soft and hard limits
  • Item – the item that will be limited – core size, file size, nproc etc
  • Value – this is the value for the given limit

A good sample for a limit is:

The above line sets a hard limit of maximum 20 processes on the «student» group.

If you want to see the limits of a certain process has you can simply “cat” the limits file like this:

Читайте также:  Install gnome manjaro linux

Where PID is the actual process ID, you can find out process id by using ps command. For more detailed explanation, read our article that says – Find Running Linux Processes and Set Process Limits Per-User Level

Sample Output
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 32042 32042 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 32042 32042 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us

All of the lines are pretty much self explanatory. However if you want to find more the settings you can input in limits.conf file, you can have a look at the manual provided here.

If you have any questions or comments, please do not hesitate to submit them in the comment section below.

Источник

limits.conf и лимиты потребления

limits.conf — файл в Linux системах в котором можно задавать ограничения для системных пользователей, чаще всего на практике оказывается полезным ограничивать количество выделенных ресурсов центрального процессора или оперативной памяти. Файл находится на Debian подобных системах по пути /etc/security/limits.conf

limits.conf и лимиты потребления ресурсов для пользователей в Linux

Прежде всего, как выяснить процессы каких пользователей потребляют больше всего ресурсов CPU оперативной памяти.

Для текущего момента посмотреть процессы можно при помощи утилиты ps

ps aux —sort=%cpu | grep -v ‘root’ | head -n 35

ps aux —sort=%mem | grep -v ‘root’ | head -n 35

Команды выведут сортированные списки процессов в одной из колонок каждого списка будет указано имя пользователя. Процессы, запущенные от имени root показываться не будут и выведутся только 35 самых активных процессов.

Пример вывода для cpu:

limits.conf

Пример вывода для mem:

лимиты потребления mem для системных пользователей

Подобным образом достоверные данные получить не удастся, например, для веб-сервера с mod_php, процессы всех пользователей при такой конфигурации будут запускаться от имени пользователя с правами которого работает веб-сервер.

В большинстве случаев в выводе как раз та информация, которая нужна для того чтобы выбрать пользователей для которых нужно предусмотреть ограничения.

Читайте также:  Enable https on linux server

Ограничения нужны на нагруженных серверах, они существуют, например, у каждого хостинг провайдера.

Лимитировать количество процессов можно используя механизм ядра cgroups — на практике проще всего установить ограничения отредактировав файл /etc/security/limits.conf и перезагрузив сервер.

Изменять /etc/security/limits.conf может только пользователь root или другой пользователь работающий из под sudo

Файл хорошо задокументирован, вся необходимая информация находится в нем в комментариях, правила меняются с помощью любого текстового редактора

В общем виде любое правило выглядит так:

domain — это пользователь или группа, для которых лимитируем ресурсы

type — тип ограничения: soft или hard, ограничение soft может быть переопределено пользователем.

item — ресурс, который ограничиваем — обычно это cpu (в минутах) или as — максимальное количество оперативной памяти (в Кб); также можно задать nice level, который не сможет быть превышен процессами пользователя/группы (минимум 20, максимум -19); здесь же можно задать chroot (только для debian)

item — само численное значение

Для того чтобы изменения вступили в силу нужна перезагрузка.

ulimit в Linux и ограничение ресурсов для пользователя

Soft лимиты пользователь может переопределить используя ulimit

Выполнение команды с аргументом -a выведет актуальные ограничения

ulimit -as 1500000
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 14685
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 14685
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

Ключи из вывода можно брать и использовать в командах, которые будут задавать ограничения для текущей терминальной сессии.

Дополнительно следует указывать тип ограничения:

Если не указывать ничего лимиты будут заданы жестко. hard здесь можно задать для текущего пользователя даже без прав root, но изменения не сохранятся после перезагрузки и чтобы ограничения были установлены постоянно нужно редактировать файл, который был рассмотрен ранее.

Создадим ограничение по оперативной памяти в 1500 Мб для пользователя

ulimit set soft limit

Выполнив ulimit -Sm или ulimit -a сейчас можно увидеть, что ограничение установлено.

Получить ту же информацию можно просмотрев лимиты для процесса

Можно указывать идентификатор любого процесса, запущенного от имени пользователя, для которого задали ограничение по памяти

Источник

Оцените статью
Adblock
detector