I don't know how to debug after the process after calling execle
. I've looked at other websites and some suggested using set fork-follow-mode child
, which helped me get into the fork. However, after the fork, I exit into the main function and never get into the program I am exec'ing.
Here is the code:
} else if (!(pid_T2 = fork())) {
char **env = NULL;
char *units_env = NULL;
char *sleep_env = NULL;
size_t sleep_sz = 16;
env = (char **) malloc(3 * sizeof(char *));
sleep_env = (char *) malloc(sleep_sz * sizeof(char));
snprintf(sleep_env, sleep_sz, "TSTALL=%d", cmd_args->sleep_num);
if (cmd_args->kb) {
units_env = "UNITS=1";
} else {
units_env = "UNITS=0";
}
*(env) = units_env; *(env + 1) = sleep_env; *(env + 2) = "TMOM=0";
/*printf("%s %s\n", *(env), *(env + 1));*/
close(pipe_A2toT2[1]);
dup2(pipe_A2toT2[0], 0);
close(pipe_A2toT2[0]);
execle("totalsize", "totalsize", NULL, env); //Exits to main after this line, never goes into program.
}
I know that the process image gets replaced by exec call, however why am I still exiting to this program's main instead of going into totalsize
program?