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>
- #include <fcntl.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==2) //xterm child
- {
- int output=open("pipa.in",O_WRONLY);//atoi(argv[1]);
- int input=open("pipa.out",O_RDONLY);//atoi(argv[2]);
- printf("input: %d | output: %d\n",input,output);
- pthread_t t1,t2;
- pthread_create(&t1,NULL,&thoutput,(void*)output);
- pthread_create(&t1,NULL,&thinput,(void*)input);
- while (1);
- }
- //pipe(fdin);
- //pipe(fdout);
- if (fork()>0) //parent
- {
- fdin[0]=open("pipa.in",O_RDONLY);
- fdout[1]=open("pipa.out",O_WRONLY);
- 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],"child"/*,argbuf,buf2*/,(char*)0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement