Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I would like to know in fork can a single parent have n number of child process or is there any constraint, and what is the maximum child process can a parent can hold or is this achievable in vfork().
Posted

I would use fork, since vfork has its caveats. Here an example "Multiple child process" question at Stack Overflow[^].
I suppose you may directly test how many child process can be generated on your system (try to generate child processes until fork returns -1).
 
Share this answer
 
A process can have multiple forked childs. It is an often used method (e.g. for web servers like Apache).

There is no specific limit for the number of child processes. There is only a limit for the number of processes for each user. You can get that limit on the command line by typing
ulimit -u

To get the value by code, use getrlimit()[^] with resource RLIMIT_NPROC:
Quote:
RLIMIT_NPROC
The maximum number of processes (or, more precisely on Linux,
threads) that can be created for the real user ID of the
calling process. Upon encountering this limit, fork(2) fails
with the error EAGAIN. This limit is not enforced for
processes that have either the CAP_SYS_ADMIN or the
CAP_SYS_RESOURCE capability.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900