Re: Maximum number of processes in Linux

From: linux-os (Dick Johnson)
Date: Wed Aug 16 2006 - 07:31:25 EST

On Wed, 16 Aug 2006, Helge Hafting wrote:

> linux-os (Dick Johnson) wrote:
>> Yep....
>> #include <stdio.h>
>> #include <signal.h>
>> int main()
>> {
>> unsigned long i;
>> for(i = 0; ; i++)
>> {
>> switch(fork())
>> {
>> case 0: // kid
>> pause();
>> break;
>> case -1: // Failed
>> printf("%lu\n", i);
>> kill(0, SIGTERM);
>> exit(0);
>> default:
>> break;
>> }
>> }
>> return 0;
>> }
>> Shows a consistent 6140.
> Doesn't work here. Without ulimit, I wasn't surprised
> about the resulting OOM mess.
> Problem was, it never stopped. I expected OOM to kill
> this program, and quite possibly lots of other running programs
> as well. What I got, was ever-rolling OOM messages
> with stack traces inbetween.
> 2.6.18-rc4-mm1 never recovered and had to be killed by sysrq.
> Helge Hafting

Script started on Wed 16 Aug 2006 07:18:48 AM EDT
LINUX> gcc -o xxx xxx.c
LINUX> ./xxx
LINUX> ./xxx
LINUX> ./xxx
LINUX> ulimit
LINUX> uname -r
LINUX> cat /proc/meminfo
MemTotal: 774572 kB
MemFree: 381984 kB
Buffers: 154120 kB
Cached: 31000 kB
SwapCached: 0 kB
Active: 74908 kB
Inactive: 130816 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 774572 kB
LowFree: 381984 kB
SwapTotal: 907664 kB
SwapFree: 907660 kB
Dirty: 28 kB
Writeback: 0 kB
Mapped: 34100 kB
Slab: 177948 kB
CommitLimit: 1294948 kB
Committed_AS: 31080 kB
PageTables: 804 kB
VmallocTotal: 515796 kB
VmallocUsed: 3524 kB
VmallocChunk: 511568 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 4096 kB
LINUX> exit
Script done on Wed 16 Aug 2006 07:19:48 AM EDT

Runs fine here. I'm using Maybe your kernel version still
has an OEM bug???

Since the forked process never touches any of its memory, it
shouldn't use anything except space in the kernel for a new task-
structure and space in user-space for stack. COW wouldn't have
happened yet. I don't see how you get out of memory before you
run out of PIDs!

The first instance of the fork failing should cause a signal
to be sent to all the children, killing them:

case -1: // Failed
printf("%lu\n", i);
kill(0, SIGTERM);

I can set /proc/sys/vm/overcommit_memory to either 1 or 0 with
the same effect, no out-of-memory errors. Maybe your kernel
version has a bug?

Dick Johnson
Penguin : Linux version on an i686 machine (5592.62 BogoMips).
New book:

The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@xxxxxxxxxxxx - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at