You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
633 B
41 lines
633 B
#include <gmt.h> |
|
#include <iostream> |
|
#include <string> |
|
#include <unistd.h> |
|
#include <sys/wait.h> |
|
#include <pthread.h> |
|
#include <sched.h> |
|
|
|
int print_func(FILE* fd, const char* str) |
|
{ |
|
std::cout<<"PRINT: "<<str<<std::endl; |
|
return 0; |
|
} |
|
|
|
void* thr(void* p) |
|
{ |
|
std::cout<<"Thread Phase1\n"; |
|
close(1); |
|
unshare(CLONE_FILES); |
|
std::cout<<"Thread Phase2\n"; |
|
dup2(*(int*)p,1); |
|
std::cout<<"Thread Phase3\n"; |
|
return 0; |
|
} |
|
|
|
|
|
int main() |
|
{ |
|
int savefd; |
|
pthread_t t; |
|
|
|
std::cout<<"Phase1\n"; |
|
savefd=dup(1); |
|
pthread_create(&t,0,&thr,&savefd); |
|
pthread_join(t,0); |
|
std::cout<<"Phase2\n"; |
|
dup2(savefd,1); |
|
std::cout<<"Phase3\n"; |
|
|
|
return 0; |
|
}
|
|
|