Michael Uleysky
9 years ago
1 changed files with 12 additions and 33 deletions
@ -1,41 +1,20 @@
|
||||
#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; |
||||
void* gmtapi; |
||||
char* text="GMT"; |
||||
char* args="-R130/160/40/60 -JM12c -Xa2c -Ya2c -B5/5/swNE ->/proc/cmdline"; |
||||
struct GMT_OPTION* opts; |
||||
int ret; |
||||
|
||||
gmtapi=GMT_Create_Session(text,2,1,0); |
||||
opts=GMT_Create_Options(gmtapi,0,args); |
||||
ret=GMT_Call_Module(gmtapi,"psbasemap",GMT_MODULE_OPT,opts); |
||||
printf("%i\n",ret); |
||||
|
||||
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"; |
||||
GMT_Destroy_Options(gmtapi,&opts); |
||||
GMT_Destroy_Session(gmtapi); |
||||
|
||||
return 0; |
||||
} |
||||
|
Loading…
Reference in new issue