• 0

[C++] help with threads


Question

Im doing a simple exercise using threads but I have a small problem: after I execute an execvp call and the command is executed my program just finish.

using namespace std;

void *test(void* args){

     char *cmd[] = { "ls", "-l", (char *)0 };

     int ret = execvp ("ls", cmd); //output ends after this line

     cout << "END thread function" << endl;
}


main (){
	pthread_t t1;
	pthread_create(&t1, NULL, test, NULL);
	pthread_join(t1, NULL);

	cout << "END";
	exit(0);
}

Output:

[kp@localhost cpp]$ ./test
total 36
-rwxrwxr-x  1 kp kp  7494 Oct 31 14:35 test
-rw-rw-r--  1 kp kp   428 Oct 31 14:35 test.cpp
-rw-rw-r--  1 kp kp   428 Oct 31 14:35 test.cpp~
-rwxrwxr-x  1 kp kp 10468 Oct 31 14:12 trgrep
-rw-rw-r--  1 kp kp  3842 Oct 31 14:13 trgrep.cpp
-rw-rw-r--  1 kp kp  3879 Oct 31 14:12 trgrep.cpp~
[kp@localhost cpp]$

I dont know whats wrong, everything compiles with no errors.

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.