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.

30 lines
860 B

12 months ago
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
void main(void) {
char saludoPadre[]="Buenos días hijo.\0";
char buffer[30];
int fd[2]; // 0 lectura y 1 escritura
pipe (fd); // creamos el pipe
pid_t pid;
pid = fork(); // se crea el proceso hijo
switch(pid) {
case -1: // error printf("Algo falló ...");
exit(-1);
break;
case 0: // soy el hijo
close(fd[1]); // cierra el descriptor de escritura = entrada
read(fd[0], buffer, sizeof(buffer));
printf("\tEl hijo recibe algo del pipe: %s\n",buffer);
break;
default: // padre envía
close(fd[0]);
write(fd[1],saludoPadre, strlen(saludoPadre)); //escribo en pipe
printf("El padre envía el mensaje al hijo ...\n");
wait(NULL);
break;
}
}

Powered by INFORMATICA.FP.EDU.ES.