QNX RTOS v4 Knowledge Base
QNX RTOS v4 Knowledge Base
Title |
Number of child processes |
Ref. No. |
QNX.000009722 |
Category(ies) |
Utilities, Configuration |
Issue |
When using fork(), how many child processes can be created by one parent process?
|
Solution |
There is no specific limitation on the number of children for a specific parent. It will create children until it hits the system maximum number of processes(specified by the -p option to Proc32, default is 500).
For example:
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <process.h> #include <sched.h> #include <sys/qnx_glob.h>
void main(int argc, char *argv[], char *envp[]){ x09int i = 0; x09pid_t pid; x09while(1){ x09x09pid = fork(); x09x09if (pid <0){ x09x09x09printf("pid %d forked %d children n, getpid(), i); x09x09x09exit(0); x09x09}else if (pid > 0){ x09x09x09i++; x09x09}else{ x09x09/*child*/ x09x09x09setprio(0, 1); x09x09x09while(1); x09x09} x09} }
This gives the result:
pid 11032 forked 352 children
x09 |
|