You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
710 B

12 months ago
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
void main(void) {
int fd[2]; // 0 lectura y 1 escritura
char buffer[30];
pid_t pid;
pipe (fd); // creamos el pipe
pid = fork(); // se crea el proceso hijo
switch(pid) {
case -1: // error
printf("Algo falló ...");
exit(-1);
break;
case 0: // soy el hijo
printf("El hijo escribe en el pipe ...\n");
write(fd[1], "Hola papi",10);
break;
default: // soy papi
wait(NULL); //espero a fin del hijo
printf("El papi lee del pipe ...\n");
read(fd[0], buffer, 10);
printf("\tMensaje recibido: %s\n", buffer);
break;
}
}

Powered by INFORMATICA.FP.EDU.ES.