I have a program that runs indefinitely. For testing purposes I have made a wrapper program that kills the other after a specified amount of time (specified via command line/terminal args). The program being forked requires that it is passed two folders with the same name (I have no control over this), so I simply pass it the same arg twice as can be seen here:
pid_t pid = fork();
if(pid == 0)
{
//build the execution string
char* test[2];
test[0] = argv[2];
test[1] = argv[2];
test[2] = NULL;
cout << "test[0] is " << test[0] << endl;
cout << "test[1] is " << test[1] << endl;
cout << "argv[1] is " << argv[1] << endl;
execvp(argv[1],test);
}
The problem is that the program being passed in argv[1] keeps segmentation faulting. If I call the by itself via the terminal it runs with no problems. I am passing the same folder in both cases. Can anyone tell me why it isn't working for execvp?
I should mention a co-worker ran it on his computer as well, and it will stand up fine the first time, but each time after that, it will seg fault.
edit: I have added a null term to test, however, this has not fixed the issue.
The command's form is exactly:
<executable> <wrapped prog> <folder> <duration>
In relative paths it's:
Intel/debug/Tester.exe <program> test 10