Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <stdlib.h>
- int main (void)
- {
- pid_t retour ;
- int tube[2], lettre = 0, chiffre = 0 ;
- char k ;
- if (pipe (tube) == -1) { perror ("creation pipe impossible\n") ; exit (1) ; }
- switch (retour = fork ()) {
- case -1 : perror ("Creation impossible") ; exit(1) ;
- case 0 :
- printf ("processus fils\n") ;
- close (tube[1]) ;
- do{
- read (tube[0], &k, 1);
- if (isdigit (k)) chiffre++ ;
- else lettre++ ;
- }while (k!='.');
- printf ("%d chiffres recus\n", chiffre) ;
- printf ("%d lettres recues\n", lettre) ;
- close (tube[0]) ;
- exit (0) ;
- default :
- printf ("pere: a cree processus %d\n", retour) ;
- close (tube[0]) ;
- while (read (0, &k, 1) >0){
- write (tube[1], &k, 1) ;
- }
- close (tube[1]) ;
- wait (0) ;
- printf ("pere: a recu terminaison fils\n") ;
- }
- return 1 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement