Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // TP_1
- //
- // Created by Samir Benjalloul on 13/10/2021.
- //
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- int main(int argc, const char * argv[]) {
- int pid;
- int s;
- int n;
- char buffer[10];
- int T[2];
- if(pipe(T) == -1){
- perror("erreur de pipe");
- exit(1);
- }
- pid = fork();//processus P1
- if(pid < 0){
- perror("error de fork");
- exit(1);
- }
- if(pid==0){ //fils
- close(T[0]);
- write(T[1], "hello", 4);
- close(T[1]);
- }else {//pére
- close(T[1]);
- n = read(T[0], buffer, 4);
- close(T[0]);
- printf("%s",buffer);
- }
- return 0;
- }
- //exit(0) cela fonctionne
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement