Any idea why the second exec isn't getting called?
int main(int argc, char* argv[]){
int fd[2];
pid_t child[2];
char *args[4];
if(argc != 3){
write(2,"Invalid # of arguments\n",23);
return 1;
}
args[0]="./generate1";
args[2]=argv[1];
args[3]=argv[2];
args[4]="0";
printf("parent: %ld\n",(long) getpid());
if(child[0] = fork())
child[1] = fork();
if(!child[0]){
printf("child: %ld\n",(long) getpid());
args[1]="even";
execvp(args[0],args);
}
if(!child[1]){
printf("child: %ld\n",(long) getpid());
args[1]="odd";
execvp(args[0],args);
}
return 0;
}
here's the output:
parent: 27052
child: 27053
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
child: 27054
int main(int argc, char* argv[]){
int fd[2];
pid_t child[2];
char *args[4];
if(argc != 3){
write(2,"Invalid # of arguments\n",23);
return 1;
}
args[0]="./generate1";
args[2]=argv[1];
args[3]=argv[2];
args[4]="0";
printf("parent: %ld\n",(long) getpid());
if(child[0] = fork())
child[1] = fork();
if(!child[0]){
printf("child: %ld\n",(long) getpid());
args[1]="even";
execvp(args[0],args);
}
if(!child[1]){
printf("child: %ld\n",(long) getpid());
args[1]="odd";
execvp(args[0],args);
}
return 0;
}
here's the output:
parent: 27052
child: 27053
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
child: 27054