Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- pipa.c 2011-04-17 11:10:57.000000000 +0000
- +++ namedpipa.c 2011-04-17 11:51:27.000000000 +0000
- @@ -2,6 +2,7 @@
- #include <stdlib.h>
- #include <stdio.h>
- #include <pthread.h>
- +#include <fcntl.h>
- void* thinput(void* input)
- {
- @@ -26,25 +27,22 @@
- int main(int argc, char** argv)
- {
- int fdin[2],fdout[2];
- -
- - if (argc==3) //xterm child
- +
- + if (argc==2) //xterm child
- {
- - int input=atoi(argv[2]);
- - int output=atoi(argv[1]);
- - printf("input: %d | output: %d\n",input,output);
- + int output=open("pipa.in",O_WRONLY);
- + int input=open("pipa.out",O_RDONLY);
- pthread_t t1,t2;
- - pthread_create(&t1,NULL,&thinput,(void*)input);
- pthread_create(&t1,NULL,&thoutput,(void*)output);
- + pthread_create(&t1,NULL,&thinput,(void*)input);
- 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]);
- + fdin[0]=open("pipa.in",O_RDONLY);
- + fdout[1]=open("pipa.out",O_WRONLY);
- pthread_t t1,t2;
- pthread_create(&t1,NULL,thinput,(void*)fdin[0]);
- pthread_create(&t1,NULL,thoutput,(void*)fdout[1]);
- @@ -52,9 +50,6 @@
- }
- 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);
- + execlp("/usr/bin/xterm","xterm","-e",argv[0],"child"/*,argbuf,buf2*/,(char*)0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement