First of all, i apologise for my english... I am from Slovenia.
So, lets get to the point. I am writting a research projet at collage (Computer Science) and i am writting about clone. I done it all, but stuck on the last exercise. I must write a program, that creates n processes ( n is input number when call program in bash)... Then every new created process starts his own processes again. First new created process creates one new child, second created process creates two new childs and so on ...
My program looks somethink like this. In function main, i have loop for and inside of it i am creating n-number of clones. Then, in the function that is called when child is created (lets say it function A), i get clone's PID and PPID and write it on the screen. And here starts problem. In that function, i must somehow again create new processes with another clone, that calls another funtion ( B ), where i write PID and PPID on the screen, but everythink i am trying, only one child of a child is created. the loop in funtion A is running propretly, but it creates only one clone. I tried __WCLONE but seems to not helping.
Thanks for any answers
Here is my code:
`
#include <stdlib.h>
#include <sys/shm.h>
#include <errno.h>
#include <linux/sched.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int i;
int ppid, pid;
int **child_stack;
int counter;
int num_of_process;
void process1() {
pid=getpid();
ppid=getppid();
printf("PID(child of a child) = %d \nPPID(child of a child) = %d \n",pid, ppid);
_exit(0);
}
void process(int j) {
pid=getpid();
ppid=getppid();
printf("PID = %d \nPPID = %d \n",pid, ppid);
for(counter=0; counter<j;counter++) {
clone(process1, child_stack, CLONE_VFORK, NULL);
}
_exit(0);
}
int main(int argc, char** argv)
{
if (argc < 2) {
printf("To few parameters\n");
exit(0);
}
child_stack = (void **) malloc(16384) + 16384 / sizeof (*child_stack);
num_of_process=atoi(argv[1]);
for(i=1; i<=num_of_process; i++)
{
clone(process, child_stack, CLONE_VFORK, i);
}
exit(0);
}
`