Created
March 31, 2017 18:13
-
-
Save morsoinferno/53334a6721d937c86b162683aeb55222 to your computer and use it in GitHub Desktop.
03_pipe1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
void main() | |
{ | |
int fd[2]; | |
int msg_length; | |
char msg[100]; | |
if (pipe(fd) == -1) | |
{ | |
perror("No se pudo crear el pipe"); | |
exit(-1); | |
} | |
printf("Descriptor fd[0] = %d\n", fd[0]); | |
printf("Descriptor fd[1] = %d\n", fd[1]); | |
if (write(fd[1], "Hola pipe\n", 10) != 10) | |
{ | |
printf("No se pudo escribir en el pipe"); | |
exit(-1); | |
} | |
if ((msg_length = read(fd[0], msg, sizeof(msg))) <= 0) | |
{ | |
printf("No se pudo leer del pipe"); | |
exit(-1); | |
} | |
if (write(1, msg , msg_length) != msg_length) | |
{ | |
printf("No se pudo escribir mensaje"); | |
exit(-1); | |
} | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment