I am calling a function which will branch and execute the code of another process for me. There are multiple processes, labeled B, C, and D. I have almost identical code for creating the different processes. For some bizarre reason that I can't uncover, one of the process creation functions causes a segmentation fault. They look identical to me. Any chance someone could weigh in, maybe give me some insight into what the issue is?
void spawn_process_b(int fileID[]){
int pid;
char * argv[2];
sprintf(argv[0], "%d", fileID[0]);
sprintf(argv[1], "%d", fileID[1]);
pid = fork();
if (pid == 0)
{
execv("PipeW1", argv);
}
}
void spawn_process_c(int fileID[]){
int pid;
char * argv[2];
sprintf(argv[0], "%d", fileID[0]);
sprintf(argv[1], "%d", fileID[1]);
pid = fork();
if (pid == 0)
{
execv("PipeW2", argv);
}
}
Through putting in breakpoints with cout << "bp1" << endl; and so on, I've discovered that spawn_process_b will execute just fine. spawn_process_c will enter, but get a segfault at the first sprintf instruction. Anyone have any ideas? Originally the spawn_process_b was giving me troubles, and...my hand to God...I didn't change a thing, and it started working. I'm almost wondering if this is something that could be dependent on the environment?