Linux – Understanding the differences between pid_max, ulimit -u and thread_max

linux-kernelprocessthreadulimit

I am trying to understand the Linux processes. I'm confused on the respective terms pid_max, ulimit -u and thread_max.

What exactly is the difference between these terms? Can someone clarify the differences?

Best Answer

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 and the same. They're handled the same way by the kernel. They both occupy a slot in the task_struct data structure. A thread, by common terminology, is in Linux a process that shares resources with another process (they will also share a thread group ID). A thread in the Linux kernel is largely a conceptual construct as far as the scheduler is concerned.

Now that you understand that the kernel largely does not differentiate between a thread and a process, it should make more sense that /proc/sys/kernel/threads-max is actually the maximum number of elements contained in the data structure task_struct. Which is the data structure that contains the list of processes, or as they can be called, tasks.

ulimit is, as the name implies, a per-user limit. The -u flag is defined as "The maximum number of processes available to a single user". An element of task_struct contains the uid of the user that created the task. A per-uid count is maintained and incremented/decremented every time a task is added/removed from task_struct. So, ulimit -u indicates the maximum number of elements (processes) that one particular user is allowed to have within task_struct at any given time.

I hope that clears things up.