Can anyone help me improve my source code below? I tried fixing it but apparently, there's not much success.
#define NUM_THREADS1 1
void *go_to_website2(void *program);
void *go_to_website1(void *program)
{
char* str[3];
str[0] = (char *)program;
str[1] = "http://www.google.com"; //supposedly 2nd website to go to
str[2] = '\0';
char* new_prog = "firefox";
pthread_t th;
int rc2;
rc2 = pthread_create(&th, NULL, go_to_website2, (void *)new_prog); //2nd thread created
pthread_join(th, NULL); //wait for the second thread th to be finished
execvp(str[0], str); //go to 2nd website (google.com), unsuccessfully opened
}
void *go_to_website2(void *program)
{
char* str2[3];
str2[0] = (char *)program;
str2[1] = "http://www.yahoo.com"; //first website, successfully opened but the
str2[2] = '\0'; // threads and the program exits after this
execvp(str2[0], str2);
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS1];
int rc1, rc2;
long t;
char* prog;
prog = "firefox";
for(t = 0; t < NUM_THREADS1; t++) {
sleep(1);
printf("In main: creating thread %ld\n", t); //used this for checking
sleep(1);
rc1 = pthread_create(&threads[t], NULL, go_to_website1, (void *)prog); //create
} // first thread
pthread_exit(NULL);
}
Now I have no idea how to open more than one website. If we try to run the program above, only www.yahoo.com will be opened. When yahoo is opened, the threads and the program itself terminate. Is there a way to fix the program to open www.yahoo.com and then www.google.com afterwards? Could anyone suggest to me some concepts/strategies in using pthreads to implement for this purpose? I'm using Linux. Any answers will be greatly appreciated. Thank you!