hello friends :)
well can anybody tell me why does this code
for (i = 0; i < 10; i++){
childpid = fork();
if (0 == childpid){ /* This is the line that is different in parts A and B. */
execlp("some_prog", "some_prog", (char *)0);
exit(2);
}
else if (childpid < 0){
fprintf(stderr, "Error with fork.\n");
exit(1);
}
create children from the same parent ( the main method i assume)
and this code:
for (i = 0; i < 10; i++){
childpid = fork();
if (childpid > 0){ /* This is the line that is different in parts A and B. */
execlp("some_prog", "some_prog", (char *)0);
fprintf(stderr, "Error with exec.\n");
exit(2);
}
else if (childpid < 0){
fprintf(stderr, "Error with fork.\n");
exit(1);
}
}
Create this a child that will create a child and we will have a relation like this
Parent-->Child-->Child-->Child-->....and so on.
thank you :)