Advertisement
diegoaguilar

incisoa

May 2nd, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <errno.h>
  5. #include <sys/wait.h>
  6.  
  7. struct Estructura {
  8.  
  9. int num;
  10. char letra;
  11. }prueba;
  12.  
  13.  
  14. int main () {
  15.  
  16. struct Estructura es, l1, l2;
  17.  
  18. es.num=10;
  19. es.letra='a';
  20. int status;
  21.  
  22. pid_t pM, pR;
  23.  
  24. int tuberia[2];
  25. pipe(tuberia);
  26.  
  27. if ( (pM=fork() == 0 )) {  // Si nos encontramos en Proceso M
  28.  
  29. close(tuberia[0]);
  30. write(tuberia[1], &es, sizeof(struct Estructura));
  31. }
  32.  
  33. else if (pM>0) {
  34.  
  35. if (( pR=fork() == 0 )) {
  36.  
  37. close(tuberia[0]);
  38. write(tuberia[1], &es, sizeof(struct Estructura));
  39. }
  40.  
  41. if (pR>0) {
  42. wait(&status);
  43. close(tuberia[1]);
  44. read(tuberia[0], &l1, sizeof(struct Estructura));
  45. printf("%d\n%c", l1.num, l1.letra);
  46. read(tuberia[0], &l2, sizeof(struct Estructura));
  47. printf("%d\n%c", l2.num, l2.letra);
  48.  
  49. }
  50. }
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement