Creating more processes with fork()

Hello people

I need help

How to make ONE process to create MORE (not one) processes with fork(). I tried several codes but do not work.

Thanks

Why not post the code you have as I cant understand what you are trying to get at here...

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main () {
pid_t childpid= 0;
int i, n=4;

for (i= 1; i< n; i++)
if (childpid= fork()) break;
wait();
printf("i:%d process ID:%ld parent ID:%ld child ID:%ld\n", i, (long)getpid(),(long)getppid(), (long)childpid); return 0;
}

output:
i:4 process ID:2129 parent ID:2128 child ID:0
i:3 process ID:2128 parent ID:2127 child ID:2129
i:2 process ID:2127 parent ID:2123 child ID:2128
i:1 process ID:2123 parent ID:2122 child ID:2127

as you can see the parent is not the same

Write out the if condition such that the parent and child processes are handled by separate sections of code depending on the return code of the fork call...then you will all the children belonging to the same parent...

can you write the code please?
thanks

It's just simple logic, and being asked to do all your work for you rubs me the wrong way. Is this homework?

The fork() call returns zero in the child, and nonzero in the parent.

The child must actually exit after it's done or it will get into parts of the loop it shouldn't.

but how to do that? can you post code?

Being asked to do all your work for you rubs me the wrong way. It's simple logic -- if you can program in C at all you can do it.

Is this homework?

no it's not a homework