Code:
void run(char *bin, char *data)
{
if(fork())
{
execl(bin, bin, data, 0);
}
else
{
int pid, status;
pid = wait(&status);
}
}
.....
for(i = 0; i < 5; i++)
{
printf("test %d\n", i);
run(PATH, data);
}
output (with 'data' being different each time):
Code:
bash$ ./test
test 0
test 1
test 2
test 3
test 4
value 1 added
value 14 added
value 65 added
bash$
The purpose of my program is to run a program 5 different times with different arguments using execl() and fork() and be able to see the full output. As you can see in the above output, values for i=3 and i=4 cause the program I am running do a segmentation fault, which is what is supposed to happen, but it shows no output. I would like to see that output just like the previous outputs.
I think it is a problem with the code not fork()ing correctly, but I am unsure. Been hitting my head against a wall for days trying to figure this one out. A solution would be simply terrific.
Thanks so much,
Todd