Advertisement
AnoTest

exo1_C

Oct 13th, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  TP_1
  4. //
  5. //  Created by Samir  Benjalloul on 13/10/2021.
  6. //
  7.  
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11.  
  12.  
  13. int main(int argc, const char * argv[]) {
  14.     int pid;
  15.     int s;
  16.     int n;
  17.     char buffer[10];
  18.     int T[2];
  19.    
  20.     if(pipe(T) == -1){
  21.         perror("erreur de pipe");
  22.         exit(1);
  23.     }
  24.    
  25.     pid = fork();//processus P1
  26.     if(pid < 0){
  27.         perror("error de fork");
  28.         exit(1);
  29.     }
  30.     if(pid==0){ //fils
  31.         close(T[0]);
  32.         write(T[1], "hello", 4);
  33.         close(T[1]);
  34.        
  35.     }else {//pére
  36.         close(T[1]);
  37.         n =  read(T[0], buffer, 4);
  38.         close(T[0]);
  39.         printf("%s",buffer);
  40.     }
  41.     return 0;
  42. }
  43.  
  44.  
  45. //exit(0) cela fonctionne
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement