Advertisement
hejmus

Untitled

Apr 17th, 2011
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.42 KB | None | 0 0
  1. --- pipa.c  2011-04-17 11:10:57.000000000 +0000
  2. +++ namedpipa.c 2011-04-17 11:51:27.000000000 +0000
  3. @@ -2,6 +2,7 @@
  4.  #include <stdlib.h>
  5.  #include <stdio.h>
  6.  #include <pthread.h>
  7. +#include <fcntl.h>
  8.  
  9.  void* thinput(void* input)
  10.  {
  11. @@ -26,25 +27,22 @@
  12.  int main(int argc, char** argv)
  13.  {
  14.     int fdin[2],fdout[2];
  15. -  
  16. -   if (argc==3) //xterm child
  17. +
  18. +   if (argc==2) //xterm child
  19.     {
  20. -       int input=atoi(argv[2]);
  21. -       int output=atoi(argv[1]);
  22. -       printf("input: %d | output: %d\n",input,output);
  23. +       int output=open("pipa.in",O_WRONLY);
  24. +       int input=open("pipa.out",O_RDONLY);
  25.         pthread_t t1,t2;
  26.        
  27. -       pthread_create(&t1,NULL,&thinput,(void*)input);
  28.         pthread_create(&t1,NULL,&thoutput,(void*)output);
  29. +       pthread_create(&t1,NULL,&thinput,(void*)input);
  30.         while (1);
  31.     }
  32. -
  33. -   pipe(fdin);
  34. -   pipe(fdout);
  35.    
  36.     if (fork()>0) //parent
  37.     {
  38. -       printf("pt:R:%d W:%d | R:%d W:%d\n",fdin[0],fdin[1],fdout[0],fdout[1]);
  39. +       fdin[0]=open("pipa.in",O_RDONLY);
  40. +       fdout[1]=open("pipa.out",O_WRONLY);
  41.         pthread_t t1,t2;   
  42.         pthread_create(&t1,NULL,thinput,(void*)fdin[0]);
  43.         pthread_create(&t1,NULL,thoutput,(void*)fdout[1]);
  44. @@ -52,9 +50,6 @@
  45.     }
  46.     else //child
  47.     {
  48. -       char argbuf[30],buf2[30];
  49. -       sprintf(argbuf,"%d",fdin[1]);
  50. -       sprintf(buf2,"%d",fdout[0]);
  51. -       execlp("/usr/bin/xterm","xterm","-e",argv[0],argbuf,buf2,(char*)0);
  52. +       execlp("/usr/bin/xterm","xterm","-e",argv[0],"child"/*,argbuf,buf2*/,(char*)0);
  53.     }
  54.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement