Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // Exercice2_Test
- //
- // Created by Samir Benjalloul on 14/10/2021.
- //
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- int main(int argc, const char * argv[]) {
- int pid;
- char buffer[10];
- int pipe1[2];
- int pipe2[2];
- int s;
- if(pipe(pipe1)== -1){
- perror("erreur de pipe 1");
- exit(1);
- }
- if(pipe(pipe2) == -1){
- perror("Erreur de pipe 2");
- exit(1);
- }
- pid =fork();
- if(pid < 0){
- perror("erreur de fork");
- exit(1);
- }
- if(pid ==0){ //fils
- close(pipe1[0]);
- close(pipe2[1]);
- read(pipe2[0], buffer, 20);
- write(pipe1[1], "hello pipe1\n",20);
- // close(pipe2[1]);
- close(pipe1[1]);
- close(pipe2[0]);
- printf("message reçus de pipe 2 %s \n", buffer);
- }else {
- close(pipe1[1]);
- close(pipe2[0]);
- write(pipe2[1],"hello pipe2\n", 20);
- read(pipe1[0], buffer, 20);
- close(pipe1[0]);
- close(pipe2[1]);
- printf("message reçu de pipe 1 %s \n",buffer);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement