|
|
@ -4,6 +4,7 @@ |
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
|
#include <sys/wait.h> |
|
|
|
#include <sys/wait.h> |
|
|
|
#include <pthread.h> |
|
|
|
#include <pthread.h> |
|
|
|
|
|
|
|
#include <sched.h> |
|
|
|
|
|
|
|
|
|
|
|
int print_func(FILE* fd, const char* str) |
|
|
|
int print_func(FILE* fd, const char* str) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -15,7 +16,10 @@ void* thr(void* p) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::cout<<"Thread Phase1\n"; |
|
|
|
std::cout<<"Thread Phase1\n"; |
|
|
|
close(1); |
|
|
|
close(1); |
|
|
|
|
|
|
|
unshare(CLONE_FILES); |
|
|
|
std::cout<<"Thread Phase2\n"; |
|
|
|
std::cout<<"Thread Phase2\n"; |
|
|
|
|
|
|
|
dup2(*(int*)p,1); |
|
|
|
|
|
|
|
std::cout<<"Thread Phase3\n"; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -27,7 +31,7 @@ int main() |
|
|
|
|
|
|
|
|
|
|
|
std::cout<<"Phase1\n"; |
|
|
|
std::cout<<"Phase1\n"; |
|
|
|
savefd=dup(1); |
|
|
|
savefd=dup(1); |
|
|
|
pthread_create(&t,0,&thr,0); |
|
|
|
pthread_create(&t,0,&thr,&savefd); |
|
|
|
pthread_join(t,0); |
|
|
|
pthread_join(t,0); |
|
|
|
std::cout<<"Phase2\n"; |
|
|
|
std::cout<<"Phase2\n"; |
|
|
|
dup2(savefd,1); |
|
|
|
dup2(savefd,1); |
|
|
|