ASR31-valarche-2021/Exemples/06-Tubes/upipe.c

28 lines
540 B
C
Raw Permalink Normal View History

2021-10-13 08:43:24 +02:00
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#define R 0
#define W 1
int main ( ) {
int fd[2] ;
char message[100] ;
int nboctets ;
char *phrase = " message envoye au pere par le fils " ;
pipe ( fd ) ;
if (fork() == 0) {
close ( fd[R] ) ;
write ( fd[W] , phrase , strlen (phrase) + 1 ) ;
close ( fd[W] ) ;
}
else {
close ( fd[W] ) ;
nboctets = read ( fd[R] , message , 100 ) ;
printf ( " Lecture %d octets : %s\n" , nboctets , message ) ;
close ( fd [R] ) ;
}
return 0;
}