Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <pthread.h>
- void* thinput(void* input)
- {
- char b;
- while (1)
- {
- read((int)input,&b,1);
- write(0,&b,1);
- }
- }
- void* thoutput(void* output)
- {
- char b;
- while (1)
- {
- read(1,&b,1);
- write((int)output,&b,1);
- }
- }
- int main(int argc, char** argv)
- {
- int fdin[2],fdout[2];
- if (argc==3) //xterm child
- {
- int input=atoi(argv[2]);
- int output=atoi(argv[1]);
- printf("input: %d | output: %d\n",input,output);
- pthread_t t1,t2;
- pthread_create(&t1,NULL,&thinput,(void*)input);
- pthread_create(&t1,NULL,&thoutput,(void*)output);
- while (1);
- }
- pipe(fdin);
- pipe(fdout);
- if (fork()>0) //parent
- {
- printf("pt:R:%d W:%d | R:%d W:%d\n",fdin[0],fdin[1],fdout[0],fdout[1]);
- pthread_t t1,t2;
- pthread_create(&t1,NULL,thinput,(void*)fdin[0]);
- pthread_create(&t1,NULL,thoutput,(void*)fdout[1]);
- while (1);
- }
- else //child
- {
- char argbuf[30],buf2[30];
- sprintf(argbuf,"%d",fdin[1]);
- sprintf(buf2,"%d",fdout[0]);
- execlp("/usr/bin/xterm","xterm","-e",argv[0],argbuf,buf2,(char*)0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement