I'm working on the 1 server-multiple client code to transfer file using socket, I'm using fork() to create new process for each client that connects to server. my question: is there any limit for fork() function to how much new process it can create?
-
1There are limits. The most relevant is usually the amount of physical memory in your server. Another limit is the maximum number of [simultaneous processes supported by your operating system](https://stackoverflow.com/q/9361816/13860), but it's unlikely you'd hit that before running out of memory. – Jonathan Hall Jan 12 '21 at 16:08
-
1A specific user might be limited by the policy as well – Eugene Sh. Jan 12 '21 at 16:09
-
Does this answer your question? [how many processes can be created with python os.fork()](https://stackoverflow.com/questions/20452150/how-many-processes-can-be-created-with-python-os-fork) – Jonathan Hall Jan 12 '21 at 16:09
2 Answers
There is not a specific limit if not the memory you have available. Since when you do a fork
you're creating a new address space (which is a copy of that of the father) you obviusly can't create any more processes if those resources start to run out (EANOMEM
error).
I also think, but not sure, there may be a default limit to the number you can spawn, set by the OS.

- 409
- 4
- 9
-
The process table does have a maximum size. Historically you ran out of memory first unless somebody called `fork()` in a loop from a tiny process, but with tens of GB on modern systems you really can hit the process table limit first. It's in the tens of thousands, well above any legit use. – Joshua Jan 12 '21 at 16:36
is there any limit for fork() function to how much new process it can create?
On systems I'm familiar with, there's no real limit to the number of processes that fork()
can create; that said, there are obviously practical limits to the number of processes that a given machine can support. Each process consumes resources, which are never unlimited.
Back when computer science students had to work in computer labs, the worst week of the semester was always when the Operating Systems class got an assignment asking them to recursively fork some number of processes (e.g. 32). Students would of course always forget to include some base case to stop the recursion, causing them to fork thousands of processes and bring the machines (which were shared) to a crawl, requiring them to be rebooted.

- 124,013
- 19
- 183
- 272